Penguin
Note: You are viewing an old revision of this page. View the current version.

Sort a directory of mp3s into directories like Artist/Album Name/

    for file in *.mp3; do
        eval $( id3tool "$file" | sed 's/^[^:]* //; s/:[\t ]*/="/; s/[[:cntrl:]]//g; /./!d; s/ *$/"/' )
        { [ "$Artist" -o "$Album" ] && dir="$Artist/$Album/" ; } || { [ "$Artist" ] && dir="$Artist/" ; } || continue
        mkdir -p "$dir" ; mv "$file" "$dir/"
    done

It uses id3tool to read the ID3? tag, instructs SED to massage the information into something that looks like Shell script, executes that to put values into variables, checks which variables are set, and if at least an artist name (optionally also album name) is given, moves the file into that directory. (It's rather a mouthful for a oneliner, but hey.)


Refresh the all GPG keys from the KeyServer without flooding it:

    for uid in $( gpg --with-colons --list-keys | grep ^pub | awk -F: '{print $5}' ) ; do gpg --refresh $uid ; sleep 5 ; done

Alter the number after sleep(1) to change the speed of the refresh. This is equalivent to the slightly more understandable:

    for uid in $( gpg --with-colons --list-keys | grep ^pub | awk -F: '{print $5}' ) ; do
        gpg --refresh $uid
        sleep 5
    done

Notes by AristotlePagaltzis:

This is a useless use of grep. Better written as follows:

    for uid in $( gpg --with-colons --list-keys | awk -F: '/^pub/{ print $5 }' ) ; do gpg --refresh $uid ; sleep 5 ; done

which can be abbreviated as

    gpg --with-colons --list-keys | awk -F: '/^pub/{ print $5 }' | xargs -ri sh -c 'gpg --refresh {} ; sleep 5'

It's a pity xargs(1) doesn't offer any speed controls itself, in that case the ugly roundabout via shell wouldn't be necessary.