Linux command to create tar archive:
tar czf mytarball.tar.gz /path/to/my/files
Linux command to convert vertical line in to horizontal line:
echo $(xargs < filename)
cat filename|tr '\n' '\t'
Linux command to join pdf (Need to install pdftk (pdf tool kit))
i)pdftk file1.pdf file2.pdf cat output output.pdf
ii) gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=combinedpdf.pdf -dBATCH 1.pdf 2.pdf 3.pdf
Linux command to find the line number of searching test "help" written in a file "filename":
nl filename | grep "help"
grep -n "help"
Linux command to resize an image, blur, crop, despeckle, dither, draw on, flip, join, re-sample,
mogrify [options] input-file
Using pdfcrop to Remove White Margins | Ubuntu
pdfcrop input.pdf output.pdf
Convert pdf file into JPEG for every single page of the original document. To improve the quality, one can try some options:
convert -colorspace RGB -interlace none -density 300X300 -quality 100 File.pdf Fig.jpg
convert -density 300 band-str-HSE06_multi.pdf -background white -quality 90 -flatten Fe3Se4_BS_HSE06.png
JOIN PNG files VERTICALLY
convert -append *.png outfile.png
JOIN PNG FILES Horizontally
convert +append *.png outfile.png
Invert the sense of matching, to select non-matching lines from file file.dat
grep -v 'k' file.dat
Sort command in unix prints lines in sorted order, -n option for numerically sorting and -k2 option sort using the 2nd column of the data, -r option for reverse sorting.
sort -nk2 file.dat
DELETE all files in current folder of size 0
find ./ -size 0 -print -delete
Encrypting files with command gpg:
gpg -c file-name
After pressing enter, prompt will ask for password.
Data can be extracted from encrypted file by using following command:
gpg file-name
Command to delete file of size 0
find ./ -name 'file.txt' -size 0 -deleteCommand to join images in to one
sed replace word / string syntax
sed -i 's/old-word/new-word/g' *.txt
SED: inserts the contents of file.txt at line 41 of main.txt, printing everything to standard output.
sed '41r file.txt' main.txt
Add audio track in video
ffmpeg -i output.mp4 -i happybday.mp3 -vf scale=720:-1 -acodec copy -threads 12 -r 30 -sameq output2.mp4
Command to find the files with different extensions and remove them.
rm -f `find . -type f \( -name "*.wfn" -o -name "*.restart" -o -name "*.wfn*" -o -name "*.restart*" \)`
or
find . -type f \( -name "*.wfn" -o -name "*.restart" -o -name "*.wfn*" -o -name "*.restart*" \) -exec rm -f {} \;
Find the files that do not match a pattern (find all files not ending with that extension)
find . -type f -not -name "*.html"
Llist all files not having a given extension. For example, if you want to list all files except the .txt files, then either
find -not -iname "*.txt"
Find and Replace in the file (open with vi editor)
Use percentage character % to search and replace the pattern in the entire file. The % indicates a range from the first to the last line of the file: (replacing x with y )
:%s/x/y/g
Find all the file in /path and removed.
find /path -type f -print | xargs rm or find /path -type f -exec rm '{}' \; or find /path -type f -exec rm '{}' +
To move only files from the Download folders, but not from sub-folders:If you want to move all files from the Downloads folder, but not any files within folders in the Download folder, use this command:
find ~/Downloads/ -maxdepth 1 -type f -print0 | xargs -0 mv -t ~/Videos
-maxdepth option specifies how deep find should try, 1 means, only the directory specified in the find command.
You can try using 2, 3 also to test.
rsync command:
To copy the myfiles directory from local system to a remote server with the address example.com, using the username as the remote user, and place the files in the /home/username/data r
$sync -avz -e ssh myfiles username@example.com:/home/username/data
Exclude specific files or directories using the --exclude option.
$rsync -av --exclude='*.log' source_directory/ destination_directory/