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 mp3 from sorted by
Terminal - Commands tagged mp3 - 49 results
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.

MP3TAG_DECODE_UTF8=0 mp3info2 -p "%a - %l\n" -R . | sort | uniq
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

for x in *.mp3; do y=`echo $x | sed 's/...\(.*\)/\1/' | sed 's/.mp3//ig'`; id3v2 --TIT2 "$y" "$x"; done
2011-11-17 18:57:09
User: robotmachine
Functions: sed
Tags: bash Linux mp3 id3
0

Assumes that the files are named as such: 01-Filename.mp3

If your files are named differently, change the number of periods in the sed 's/...\(.*\)/\1' bit to match the numbers of characters you need to cut off the front of the file.

Note: This only writes the titles.

x="1" && z="`ls -l * | wc -l`"; for y in *.mp3; do `id3v2 --TRCK "$x/$z" "$y"`; x=$[$x+1]; done
2011-11-17 18:52:59
User: robotmachine
Tags: Linux mp3 id3
0

Assumes that the files are named in numerical order (ie. 01 Filename.mp3). It will set the track number as tracknumber/totaltracks (ie. 1/14). This will write both ID3v1 and ID3v2 tags.

Note: This only writes the track numbers.

youtube-dl -t --extract-audio --audio-format mp3 YOUTUBE_URL_HERE
2011-11-15 20:11:20
User: menachem
Tags: youtube mp3
29

youtube-dl has this functionality built in. If you're running an older version of youtube-dl, you can update it using `youtube-dl -U` (although if you have an older version, it probably doesn't download youtube videos anyway.)

youtube-dl --help will show you other options that may come in useful.

url="put_url_here";audio=$(youtube-dl -s -e $url);wget -q -O - `youtube-dl -g $url`| ffmpeg -i - -f mp3 -vn -acodec libmp3lame - > "$audio.mp3"
2011-11-15 19:09:52
User: o0110o
Functions: wget
Tags: youtube mp3
1

Make your own MP3s from Youtube videos.

wgetall () { wget -r -l2 -nd -Nc -A.$@ $@ }
2011-09-28 09:43:25
Functions: wget
0

Recursively download all files of a certain type down to two levels, ignoring directory structure and local duplicates.

Usage:

wgetall mp3 http://example.com/download/

yt-pl2mp3() {umph -m 50 $1 | cclive -f mp4_720p; IFS=$(echo -en "\n\b"); for track in $(ls | grep mp4 | awk '{print $0}' | sed -e 's/\.mp4//'); do (ffmpeg -i $track.mp4 -vn -ar 44100 -ac 2 -ab 320 -f mp3 $track.mp3); done; rm -f *.mp4}
2011-03-20 14:43:20
User: sattellite
Functions: awk echo grep ls rm sed
0

umph is parsing video links from Youtube playlists ( http://code.google.com/p/umph/ )

cclive is downloading videos from Youtube ( http://cclive.sourceforge.net/ )

Example:

yt-pl2mp3 7AB74822FE7D03E8
ffmpeg -i input.flv -aq 2 output.mp3
2011-02-16 15:05:41
User: maedox
0

Gives stereo, 16bit, 44.1kHz (default in Ubuntu/Medibuntu ffmpeg).

-aq 2 = 220-250kbit/s VBR, lower number is better quality. 2 or 3 should be good for most people. If you want the best mp3 q you should remove -aq and use -ab 320k to get 320kbit/s, but that is probably overkill for most .flv videos.

Command in description (Your command is too long - please keep it to less than 255 characters)
2011-02-03 08:25:42
User: __
Functions: command less
0
yt2mp3(){ for j in `seq 1 301`;do i=`curl -s gdata.youtube.com/feeds/api/users/$1/uploads\?start-index=$j\&max-results=1|grep -o "watch[^&]*"`;ffmpeg -i `wget youtube.com/$i -qO-|grep -o 'url_map"[^,]*'|sed -n '1{s_.*|__;s_\\\__g;p}'` -vn -ab 128k "`youtube-dl -e ${i#*=}`.mp3";done;}

squeezed the monster (and nifty ☺) command from 7776 from 531 characters to 284 characters, but I don't see a way to get it down to 255. This is definitely a kludge!

lame rec01.wav rec01.mp3
function cp_mp3_to { PID=`pidof audacious2`; FILEPATH=`lsof -p $PID| grep mp3| sed s/[^\/]*//`; cp "$FILEPATH" "$1"; }
2010-12-06 16:31:58
User: ivanatora
Functions: cp grep sed
Tags: copy mp3
1

Maybe it could work for any music player if you change "audacious2" with the string you see in `ps aux` for your player. Needs testing in different systems.

find -iname '*mp3' -exec mid3iconv {} \;
2010-10-29 05:35:46
User: schlaegel
Functions: find
5

Some MP3s come with tags that don't work with all players. Also, some good tag editors like, EasyTAG output tags that don't work with all players. For example, EasyTAG saves the genre as a numeric field, which is not used correctly in Sansa MP3 players.

This command corrects the ID3 tags in MP3 files using mid3iconv, which comes with mutagen. To install Mutagen on Fedora use "yum install python-mutagen"

for f in *;do flac -cd $f |lame -b 192 - $f.mp3;done
ffmpeg -t 300 -r '0.5' -i head-%03d.png -i ../TvQuran.com__144.mp3 -acodec copy muxed.flv
2010-10-07 16:29:08
User: pykler
3

Creates a 5 minute flv file, with the given sequence of images and audio with 0.5 fps.

The images were created using the following command:

for x in `seq 0 300`; do cp ../head.PNG head-`printf '%03d' $x`.png; done

You can also inject metadata to seek easier using yamdi as follows:

yamdi -i muxed.flv -o video.flv

ls -w 1 > list.m3u
2010-08-27 07:03:17
User: Tungmar
Functions: ls
2

A short variant if you have only one directory whit only audio files in it.

find /DirectoryWhereMyMp3sAre/ -regextype posix-egrep -iregex '.*?\.(ogg|mp3)' | sort > ~/mylist.m3u
find . -type f -iname '*.flac' | while read FILE; do FILENAME="${FILE%.*}"; flac -cd "$FILE" | lame -b 192 - "${FILENAME}.mp3"; done
2010-08-15 19:02:19
User: paulochf
Functions: find read
7

find . -type f -iname '*.flac' # searches from the current folder recursively for .flac audio files

| # the output (a .flac audio files with relative path from ./ ) is piped to

while read FILE; do FILENAME="${FILE%.*}"; flac -cd "$FILE" | lame -b 192 - "${FILENAME}.mp3"; done

# for each line on the list:

# FILE gets the file with .flac extension and relative path

# FILENAME gets FILE without the .flac extension

# run flac for that FILE with output piped to lame conversion to mp3 using 192Kb bitrate

file /music/dir/* | grep -v 44.1 | sed 's/:.*//g' | grep .mp3 | { while IFS= read; do filebak="\"$REPLY.original\""; file="\"$REPLY\""; mv $file $filebak; sox -t mp3 $filebak $file rate 44k; done; };
2010-08-12 21:53:28
User: IgnitionWeb
Functions: file grep mv sed
Tags: mp3 sox resample
-2

This heavy one liner gets all the files in the "/music/dir/" directory and filters for non 44.1 mp3 files. After doing this it passes the names to sox in-order to re-sample those files. The original files are left just in case.

curl -L -s `curl -s [http://podcast.com/show.rss]` | xmlstarlet sel -t -m "//enclosure[1]" -v "@url" -n | head -n 1` | ssh -t [user]@[host] "mpg123 -"
2010-07-31 00:17:47
User: denzuko
Functions: head ssh
0

Gets the latest podcast show from from your favorite Podcast. Uses curl and xmlstarlet.

Make sure you change out the items between brackets.

curl -L -s `curl -s http://www.2600.com/oth-broadband.xml` | xmlstarlet sel -t -m "//enclosure[1]" -v "@url" -n | head -n 1` | ssh -t [user]@[host] "mpg123 -"
0

Ever wanted to stream your favorite podcast across the network, well now you can.

This command will parse the iTunes enabled podcast and stream the latest episode across the network through ssh encryption.