Resize Image

# Resize to max width/height 640
sips -Z 640 *.jpg

Convert Image Format

# Convert png to jpg
sips -s format jpeg *.png --out mydirectory

sips is a CLI tool included in Mac, but the commands is not pretty. If you can install other tools, magick mogrify does resizing, converting formats, and more.

List Process Running on a Port

# eg. Port 8080
lsof -i :8080

Kill Process running on a Port

lsof -P | grep ':8080' | awk '{print $2}' | xargs kill -9

Creating Markdown Journal

Uses journal:

journal new -d /path/to/journal "My entry for today"

Extract MP3 from Youtube

Uses youtube-dl:

youtube-dl -x --audio-format=mp3

# Other handy youtube-dl
# Download in mp4 video format
youtube-dl -f mp4

Download Youtube Live Stream

For live streams, youtube-dl does not work well. We need another tool to the rescue - livestreamer streamlink

streamlink --hls-live-restart -o Live.ts best

Download a file with curl

curl -o myfile.mp3

# To resume, if download was interrupted
curl -o myfile.mp3 -C -

Rename multiple files in a directory

# Add a prefix "XXX_" to every file
for f in * ; do mv "$f" "XXX_$f" ; done


# Find recursively in the directory for the string 'needle'
grep -R 'needle' path/to/dir/

Sleep and Timeout

# Start running a command (eg streamlink) after 60 seconds
sleep 60 && streamlink ...

# Run long running command (eg streamlink) and terminate after 60 seconds
gtimeout 60 streamlink ...

On macOS, you need to brew install coreutils to use gtimeout.


I usually backup my external drive data to ANOTHER external drive, just keeping as a fallback if the drive fail. To sync them, I use rsync. Mac ships with a rather outdated version, so install with brew install rsync first.

rsync -axHAWXS --numeric-ids --info=progress2 /drive/primary/ /drive/backup/

The above will sync from everything from “primary” folder to “backup” folder.




Back to Home