Skip to content

Bash recipes

Parameter expansion

Convert wav files to mp3

Remove the file extension using parameter expansion.

for file in *.wav; do ffmpeg -i "$file" -acodec mp3 "${file%.*}.mp3"; done

Loop files

Set basic ID3 tags for mp3 files

t=1; for file in *.mp3; do eyeD3 -a "Patrice O'Neal" -A 'Mr. P' -N 17 -n $t -G Comedy "$file"; ((t++)); done

Random tricks

Transfer many files over ssh

Use tar to pipe multiple files over the network into a sub-directory called my-server.

ssh my-server 'cd /var/log/; sudo tar -cvf - maillog*' | tar -xvf - -C my-server/

Last update: February 25, 2021