Skip to content

Instantly share code, notes, and snippets.

@thomascrepain
Last active January 11, 2021 19:51
Show Gist options
  • Save thomascrepain/8216248 to your computer and use it in GitHub Desktop.
Save thomascrepain/8216248 to your computer and use it in GitHub Desktop.
Command line magic Cheat Sheet - much used but not remembered
# Search & replace over multiple files (Linux)
find . -type f -print0 | xargs -0 sed -i 's/foo/bar/g'
# Search & replace over multiple files (Mac OS X)
find . -type f -print0 | xargs -0 sed -i '' -e 's/foo/bar/g'
# remove empty files in a directory
find /tmp -size 0 -print0 |xargs -0 rm
# Run command in multiple directories
for dir in ./*; do (cd "$dir" && echo "$dir" && cowsay "boo"); done
# SSH: bind remote port ([bind_address:]port:host:hostport)
ssh -L 3306:localhost:3306 root@192.168.x.x
# Xdebug on vagrantbox
ssh -R 9000:localhost:9000 vagrant@vagrant.dev
# Write disk image to SD-card
df -h
sudo umount /dev/mmcblk0p1
xzcat ~/Downloads/img-file.img.xz | sudo dd bs=4M of=/dev/mmcblk0
sudo watch kill -USR1 $(pgrep ^dd) # monitor progress
sync
# Rename jpg files based on EXIF data
find . -iname '*jpg' -exec jhead -n%Y%m%d-%H%M%S {} +
# Convert HEIC image file to jpg
magick convert foo.HEIC foo.jpg
# bulk convert multiple HEIC images to jpg
magick mogrify -monitor -format jpg *.HEIC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment