Below is a list of useful bash commands for everyday work. I have just created the repository, more contents shall be added soon.
Get bash script here.
ffmpeg -ss 20 -i input.mp3 -t 10 -c copy output.mp3
The option -ss
20 starts trimming from 20 sec of the input audio and -t
10 signifies that output audio length is 10 sec.
mp3wrap output.mp3 input1.mp3 input2.mp3
With audio re-encoding
ffmpeg -i video.mp4 -i audio.wav -c:v copy -c:a aac output.mp4
Without audio re-encoding
ffmpeg -i video.mp4 -i audio.wav -c copy output.mkv
Replacing audio stream
ffmpeg -i video.mp4 -i audio.wav -c:v copy -c:a aac -map 0:v:0 -map 1:a:0 output.mp4
ffmpeg -i video.mp4 -i subtitle.srt -c copy -c:s mov_text output.mp4
Get bash script here.
xclock -update 1 -geom 900x900
The -update
option signifies how often the clock is updated in seconds. The -geom
or -geometry
is the resolution (size) of the clock.
cal
To print the current year's calendar, use
cal -y
Putting a year after -y
prints calender of that year.
date
Simply put the URL of the file you want to download as an argument to wget
.
wget [URL]
To download file and save under specific name, run
wget -0 [name] [URL]
To download in background, run
wget -b [URL]
To resume/continue downloading a file, run
wget -c [URL]
Make a list of all the URLs (one per line) in a text file downloadlist.txt
and then run
wget -i downloadlist.txt
To reduce the size of the image input.jpg
to 40%, run
convert -resize 40% input.jpg output.jpg
The target size may also be specified:
convert -resize 720x480 input.jpg output.jpg
The following example converts image.png to image.jpg by adding a white background
convert image.png -background white -flatten -alpha off image.jpg
We are using ImageMagick here. To read metadata, use
identify -verbose /path/image.jpg | grep exif
To remove all metadata, use
mogrify -strip /path/image.jpg
Get bash script here.
convert 1.jpg 2.jpg output.pdf
To convert all JPG images in the directory, use
convert *.jpg output.pdf
To extract pages 10-12, 15 and 21-22 from input.pdf
and compile them into out.pdf
, use
pdftk input.pdf cat 10-12 15 21-22 output out.pdf
To extract images in their original formats:
pdfimages -all input.pdf /tmp/out
To extract images in JPEG:
pdfimages -j input.pdf /tmp/out
pdftk infile1.pdf infile2.pdf infile3.pdf cat output outfile.pdf
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf