Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands tagged music from sorted by
Terminal - Commands tagged music - 26 results
for i in */; do echo $(find $i -type f -regextype posix-extended -regex ".*\.(mp3|ogg|wav|flac)" | wc -l) $i ; done
find . -type d -maxdepth 1 -print0 | xargs -0 -I{} sh -c 'find "{}" -type f | grep "ogg\|mp3\|wav\|flac$" | wc -l | tr -d "\n"; echo " {}"'
2013-12-22 13:40:29
User: dbrgn
Functions: echo find grep sh tr wc xargs
0

This lists the number of ogg/mp3/wav/flac files in each subdirectory of the current directory. The output can be sorted by piping it into "sort -n".

find . -iname "*.mp3" | mpg123 -Z --list -
python2 -c 'import urllib2 as u, sys as s, json as j, subprocess as p;p.call(["mplayer", u.urlopen(j.loads(u.urlopen("http://ex.fm/api/v3/song/search/%s" % "+".join(s.argv[1:])).read())["songs"][0]["url"]).geturl().split("#")[0]])' lenny kravitz fly away
2013-09-21 02:25:51
User: nagev
Functions: as
4

Just give it an artist and/or song at the end of the command as shown.

wget -r -l1 -H -nd -A mp3 -e robots=off http://example/url
2013-07-13 02:00:23
User: trizko
Functions: wget
Tags: wget music
1

This will download all files of the type specified after "-A" from a website. Here is a breakdown of the options:

-r turns on recursion and downloads all links on page

-l1 goes only one level of links into the page(this is really important when using -r)

-H spans domains meaning it will download links to sites that don't have the same domain

-nd means put all the downloads in the current directory instead of making all the directories in the path

-A mp3 filters to only download links that are mp3s(this can be a comma separated list of different file formats to search for multiple types)

-e robots=off just means to ignore the robots.txt file which stops programs like wget from crashing the site... sorry http://example/url lol..

echo 'main(t){for(;;t++)putchar(((t<<1)^((t<<1)+(t>>7)&t>>12))|t>>(4-(1^7&(t>>19)))|t>>7);}' | cc -x c - -o crowd && ./crowd | aplay
2012-08-22 10:15:27
User: mx4492
Functions: cc echo
1

Never ending music, generated via a C snippet, piped to aplay. Taken from: http://canonical.org/~kragen/bytebeat/

ls | grep -i mp3 | sort -R | sed -e 's/.*/"&"/' | xargs mpg123
2012-03-10 20:51:36
User: retrodanny
Functions: grep ls sed sort xargs
2

* grep -i leaves only mp3 files (case insentitive)

* sort -R randomizes list (may use GNU 'shuf' instead).

* the sed command will add double quotes around each filename (needed if odd characters are present)

lame -m j -V 4 -q 0 --lowpass 17 -b 128 --cbr "infile" "128/outfile"
2011-12-22 04:49:22
0

This converts a mp3 file "infile" to a CBR 128 kbps high quality (according to Winamp) mp3 "128/outfile", joint-stereo, using LAME.

pkill -{signal} mpg321
2011-11-23 12:11:02
User: neurignacio
0

useful signals are:

pkill -SIGSTOP mpg321 #pause pkill -SIGCONT mpg321 #resume pkill -SIGHUP mpg321 #stop pkill -SIGKILL mpg321 #force exit

TIP: use aliases or shortcuts to control mpg321 from the Desktop Manager

(IFS=$'\n'; ln -sf $(awk '((NR % 2) != 0 && NR > 1) {print "prefix" $0}' list.m3u) target_folder)
2011-09-25 16:45:28
User: lxe
Functions: awk ln
1

This command will place symbolic links to files listed in an m3u playlist into a specified folder. Useful for uploading playlists to Google Music.

prefix = The full path prefix to file entries in your .m3u file, if the file paths are relative. For example, if you have "Music/folder/song.mp3" in your list.m3u, you might want to specify "/home/username" as your prefix.

list.m3u = Path to the playlist

target_folder = Path to the target folder in which you would like to create symlinks

mplayer "$(find . -maxdepth 2 -mindepth 2 -type d | grep -v '^.$' | sort -R | head -n1)"/*
2011-03-15 01:19:59
User: jedahan
Tags: music random
-3

Good if you have your music like Artist/(Year) Album/Song

for f in *;do flac -cd $f |lame -b 192 - $f.mp3;done
cp "/var/lib/mpd/music/`mpc --format '%file%' | head -n1`" /some/where/else
gst123 -z **/*
2010-05-18 13:45:41
User: eolo999
Tags: music zsh gst123
-4

Depends on zsh and gst123 ( http://space.twc.de/~stefan/gst123.php )

cd in_your_music_root_folder and then issue the command

zenity --list --width 500 --height 500 --column 'radio' --column 'url' --print-column 2 $(curl -s http://www.di.fm/ | awk -F '"' '/href="http:.*\.pls.*96k/ {print $2}' | sort | awk -F '/|\.' '{print $(NF-1) " " $0}') | xargs mplayer
2010-04-28 23:45:35
User: polaco
Functions: awk sort xargs
15

This is a very simple and lightweight way to play DI.FM stations

For a more complete version of the command with proper strings in the menu, try: (couldnt fit in the command field above)

zenity --list --width 500 --height 500 --title 'DI.FM' --text 'Pick a Radio' --column 'radio' --column 'url' --print-column 2 $(curl -s http://www.di.fm/ | awk -F '"' '/href="http:.*\.pls.*96k/ {print $2}' | sort | awk -F '/|\.' '{print $(NF-1) " " $0}') | xargs mplayer

This command line parses the html returned from http://di.fm and display all radio stations in a nice graphical menu. After the radio is chosen, the url is passed to mplayer so the music can start

dependencies:

- x11 with gtk environment

- zenity: simple app for displaying gtk menus (sudo apt-get install zenity on ubuntu)

- mplayer: simple audio player (sudo apt-get install mplayer on ubuntu)

mplayer -playlist <(find $PWD -type f)
2010-04-17 00:20:08
User: rkulla
Functions: find
0

Press > or < to go to the next or previous track. Space to toggle play/pause, etc.

It creates a temp file descriptor. To see where the file descriptor gets created type: echo <(echo foo)

This works better than running find first, then piping to mplayer with xargs or something, because that won't let you use keyboard shortcuts.

for file in *.flac; do flac -cd "$file" | lame -q 0 --vbr-new -V 0 - "${file%.flac}.mp3"; done
find . -type f -name '*.mp3' -execdir mp3gain -a '{}' +
2010-03-21 22:23:44
Functions: find
1

This normalizes volume in your mp3 library, but uses mp3gain's "album" mode. This applies a gain change to all files from each directory (which are presumed to be from the same album) - so their volume relative to one another is changed, while the average album volume is normalized. This is done because if one track from an album is quieter or louder than the others, it was probably meant to be that way.

for i in */*/*\(1\)*; do mv -f "$i" "${i/ (1)}"; done
2010-01-30 03:11:55
User: magenine
Functions: mv
1

Renames duplicates from MusicBrainz Picard, so you get the latest copy and not a bunch of duplicates.

wget -rc -A.flac --tries=5 http://archive.org/the/url/of/the/album
2010-01-20 07:36:25
User: meunierd
Functions: wget
0

The only zipped version of an album available for download is the lossy mp3 version. To download lossless files, because of their size, you must download them individually. This command scrapes the page for all the FLAC (or also SHN) files.

find . -type d -exec sh -c "normalize-audio -b \"{}\"/*.mp3" \;
2009-12-08 03:13:13
Functions: find sh
-2

Execute this in the root of your music library and this recurses through the directories and normalizes each folder containing mp3s as a batch. This assumes those folders hold an album each. The command "normalize-audio" may go by "normalize" on some systems.

mpc play $(sed -n "s@^[ >]\([0-9]\+\)) $(mpc playlist|cut -d' ' -f3-|dmenu -i -p 'song name'||echo void)@\1@p" < <(mpc playlist))
2009-10-30 16:22:10
User: gibboris
Functions: sed
1

Add a [fluxbox] binding in your key file then this

command provides a dmenu selector for the next track to play

xmms2 mlib search added \> $(echo $(date +%s) - 604800|bc)
alias somafm='read -p "Which station? "; mplayer --reallyquiet -vo none -ao sdl http://somafm.com/startstream=${REPLY}.pls'
2009-05-05 12:13:46
User: denzuko
Functions: alias
-2

This is the alias command that I discussed in my prior release which you can add to your ~/.bashrc.

This command asks for the station name and then connects to somafm, Great for those who have linux home entertainment boxes and ssh enabled on them, just for the CLI fiends out there ( I know I'm one of them ;)

You can find future releases of this and many more scripts at the teachings of master denzuko - denzuko.co.cc.

read -p "Which station? "; mplayer --reallyquiet -vo none -ao sdl http://somafm.com/startstream=${REPLY}.pls
2009-05-04 00:26:19
User: denzuko
Functions: read
11

This command asks for the station name and then connects to somafm, Great for those who have linux home entertainment boxes and ssh enabled on them, just for the CLI fiends out there ( I know I'm one of them ;)

Also, don't forget to add this as alias(ie alias somafm="read -p 'Which Station? "; mplayer --reallyquite -vo none -ao sdl