General command-line stuff

Image manipulation

Animated images
Animated gif with Imagemagick:
convert -delay 1.5 -loop 0 image.00*.bmp out.gif
note that I used the ancient bmp format to dismiss transparency.
The same with ffmpeg:
ffmpeg -f image2 -i fractureTest.%04d.bmp out.mp4
And reverse:
ffmpeg -i "" -an -f image2 "output.%05d.png"
Convert movie to gif:
ffmpeg -i -f image2pipe -vcodec ppm - | convert - -delay 0 -loop 0 dragon_pipe.gif

Proper Quicktime from image sequences:
ffmpeg -f image2 -i frame%01d.png -pix_fmt yuv420p

Really small screen captures:

ffmpeg -i -s 1600x900 -b 3000k -vcodec h264 -acodec none out.mp4

Change resolution of course to get a smaller size, and adjust bitrate accordingly.

Small gif from movie:
(main switches are -r for rate and -colors for #colors)

ffmpeg -i -r 10 -f image2pipe -vcodec ppm - | convert - -dither none -matte -depth 8 -deconstruct  -layers optimizePlus -colors 64 output.gif


ffmpeg -v warning -i $1 -vf "$filters,palettegen" -y $palette
ffmpeg -v warning -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2

Lazy one-liner:
(just change file);filters="fps=15,scale=640:-1:flags=lanczos"; palette="/tmp/palette.png"; ffmpeg -i $file -vf "$filters,palettegen" -y $palette; ffmpeg -i $file -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y ${file%.*}.gif


delete empty folders recursively

# check...
find . -type d -empty -print
# do it
find . -type d -empty -delete

Recursive find and replace Use sed in-place editing on a set of files:

find . -name "*.log" -exec sed -i '' 's/string\/with\/slash/replaced_with_this/g' {} \;


n=1;for i in *.png ; do mv $i flock$n.png; ((n=n+1)) ; done

Find out the combined size of a type:

find folder/ -name "*.jpg" -print0 | xargs -0 du -hc | tail -n1

Collapse whitespaces
echo "hey you" | tr -s ' ' | cut -d ' ' -f 2

Files modified in the last 120 min

find . -mmin -120


Lazy Tab completion
in .inputrc:
set show-all-if-ambiguous on


Detach screen
CTRL-a, then d
Name screen
screen -S name

dl youtube audio

youtube-dl -f bestaudio --extract-audio --audio-format wav http://URL_TO_VID
(or use mp3...)


an easy xargs example
find . -name "*.h" | xargs grep good_stuff