Command Line Tools

Working with audio files on the command line is a virtual necessity if you’re managing a large collection. This page contains numerous incantations useful to music enthusiasts elsewhere. By necessity it is tailored to OS X users, although most of these commands should also work on Unix-based operating systems.

Setup

First things first: ensure you are using a decent terminal and shell, and upgrade whatever software you wish to use (the defaults that ship with OS X are often years old). For this, I recommend iTerm, Oh My Zsh, and Homebrew. Some additional tools can be installed via Homebrew, for example flac and unrar.

If you aren’t sure what a shell command does, or just want to double-check you’ve set flags correctly, check out Explain Shell.

Rsync

Rsync is one of the most useful command line tools. I use it all the time to maintain local backups of my collection. Note the use of backslashes and the presence of --dry-run in most example commands. Just remove the dry run flag and you’re good to go!

Copy from one drive to another:

rsync -avh --progress --exclude={"._","._/"} /Volumes/SourceDrive/Music/ /Volumes/DestinationDrive/Music --dry-run

Rsync can also be used to compare directories recursively, a useful function after restoring from backups or copying to a new hard drive:

rsync -rv --delete /Volumes/SourceDrive/Archive/ /Volumes/DestinationDrive/Archive/ --dry-run

Find

Find has many useful features and can be combined with other commands. Add -delete to remove files and directories you’ve found with this command.

Find empty directories:

find . -depth -type d -empty

Find junk that sometimes clutters up your collection:

find . -name '.DS_Store' -type f
find . -name '*.jpg' -type f

Find corrupt files recursively:

find . -name "*.flac" -exec flac -t '{}' \; |& grep -C 1 "Got error"

This command will be time-consuming when run on large directory trees; consider writing the output to a log file:

find . -name "*.flac" -exec flac -t '{}' \; |& grep -C 1 "error" > ~/music/corrupt-flacs.log