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

Recursively scan directories for mp3s and pass them to mplayer

Terminal - Recursively scan directories for mp3s and pass them to mplayer
rm -rf /tmp/playlist.tmp && find ~/mp3 -name *.mp3 > /tmp/playlist.tmp && mplayer -playlist /tmp/playlist.tmp -shuffle -loop 0 | grep Playing
2010-03-23 21:33:44
User: hhanff
Functions: find grep rm
2
Recursively scan directories for mp3s and pass them to mplayer

The command first deletes any old playlist calles playlist.tmp under /tmp. After that it recursively searches all direcotries under ~/mp3 and stores the result in /tmp/playlist.tmp. After havin created the playlist, the command will execute mplayer which will shuffle through the playlist.

This command is aliased to

m is aliased to `rm -rf /tmp/playlist.tmp && find ~/mp3 -name *.mp3 > /tmp/playlist.tmp && mplayer -playlist /tmp/playlist.tmp -shuffle -loop 0 | grep Playing'

in my ~/.bashrc.

Alternatives

There is 1 alternative - vote for the best!

Terminal - Alternatives
$ find . -iname *.mp3 | while read line ; do ln -s "$line" $(echo -e "$line" | openssl md5).mp3 ; done ; mpg123 *.mp3

Know a better way?

If you can do better, submit your command here.

What others think

By the way: Can anybody figure out how to do the same thing without creating a temporary playlist? I tried to pass the results of find to mplayer via xargs, but then the keyboard controls of mplayer won't function any more....

Comment by hhanff 239 weeks and 1 day ago

What about 'find ~/mp3 -iname *.mp3 -exec mplayer -shuffle -loop {} \;' ? I am not at a *nix machine right now, so I can't test it, but something like this would not require a playlist.

Comment by philthomson 239 weeks and 1 day ago

The '-iname' option on find will help if you have mp3's where the extension is .MP3 as opposed to .mp3

Comment by philthomson 239 weeks and 1 day ago

My suggestion doesn't work, but I did google the problem with mplayer and found this: 'http://www.linuxquestions.org/questions/linux-software-2/xargs-mplayer-loses-key-controls-635170/' The suggested workaround only works for files with no spaces in them, but I'm sure there is some way to do it for all kinds of file names.

Comment by philthomson 239 weeks and 1 day ago

"find blablabla | mplayer -playlist -" will build a playlist from stdin. Also, you should write "\*.mp3" instead of simply "*.mp3", otherwise your shell will expand * before it gets to find, and find will get a list of *-mp3's in cwd

Comment by benjamin 239 weeks and 1 day ago

@philtomson: I found the same page yesterday but had not idea how to make it work...

@ benjamin:

find ~/mp3 -name "*.mp3" | mplayer -playlist - -shuffle -loop 0

does not allow to control mplayer with keyboard any more.... e.g. "next song" by hitting return... :/

Here's a better version which filters out all "audio books":

rm -rf /tmp/playlist.tmp && find ~/mp3 -name *.mp3 -not -name 'H?rb?cher' > /tmp/playlist.tmp && mplayer -playlist /tmp/playlist.tmp -shuffle -loop 0 | grep Playing
Comment by hhanff 239 weeks ago

Okay, this works:

for i in "$(find . -type d)";do d=( $i/*.mp3 ); files=( "${files[@]}" "${d[@]}" );done; mplayer -shuffle -loop 0 "${files[@]}"

ugly as hell though :D

Comment by benjamin 239 weeks ago

Sin!!! That's a big one...

Comment by hhanff 238 weeks and 6 days ago

Your point of view

You must be signed in to comment.

Related sites and podcasts