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 convert from sorted by
Terminal - Commands tagged convert - 76 results
ffmpeg -i video.flv audio.ogg
2012-03-05 23:43:45
User: aminehmida
0

A simple command to extract audio from flv/mp4 video file.

Just change extentions...

for fn in xkcd*.png xkcd*.jpg; do echo $fn; read xw xh <<<$(identify -format '%w %h' $fn); nn="$(echo $fn | sed 's/xkcd-\([^-]\+\)-.*/\1/')"; wget -q -O xkcd-${nn}.json http://xkcd.com/$nn/info.0.json; tt="$(sed 's/.*"title": "\([^"]\+\)",.*/\1/' ...
2012-01-06 20:26:11
User: fpunktk
Functions: echo read wget
-2

full command:

for fn in xkcd*.png xkcd*.jpg; do; echo $fn; read xw xh <<<$(identify -format '%w %h' $fn); nn="$(echo $fn | sed 's/xkcd-\([0-9]\+\)-.*/\1/')"; wget -q -O xkcd-${nn}.json http://xkcd.com/$nn/info.0.json; tt="$(sed 's/.*"title": "\([^"]*\)", .*/\1/' xkcd-${nn}.json)"; at="$(sed 's/.*alt": "\(.*\)", .*/\1/' xkcd-${nn}.json)"; convert -background white -fill black -font /usr/share/fonts/truetype/freefont/FreeSansBold.ttf -pointsize 26 -size ${xw}x -gravity Center caption:"$tt" tt.png; convert -background '#FFF9BD' -border 1x1 -bordercolor black -fill black -font /usr/share/fonts/truetype/freefont/FreeSans.ttf -pointsize 16 -size $(($xw - 2))x -gravity Center caption:"$at" at.png; th=$(identify -format '%h' tt.png); ah=$(identify -format '%h' at.png); convert -size ${xw}x$(($xh+$th+$ah+5)) "xc:white" tt.png -geometry +0+0 -composite $fn -geometry +0+$th -composite at.png -geometry +0+$(($th+$xh+5)) -composite ${fn%\.*}_cmp.png; echo -e "$fn $nn $xw $xh $th $ah \n$tt \n$at\n"; done

this assumes that all comics are saved as xkcd-[number]-[title].{png|jpg}.

it will then download the title and alt-text, create pictures from them, and put everything together in a new png-file.

it's not perfect, but it worked for nearly all my comics.

it uses the xkcd-json-interface.

though it's poorly written, it doesn't completely break on http://xkcd.com/859/

youtube-dl -o bun.flv http://www.youtube.com/watch?v=SfPLcQhXpCc; mplayer bun.flv -ss 03:16 -endpos 5 -vo jpeg:outdir=bun:quality=100:smooth=30:progressive -vf scale=320:240 -nosound; convert -delay 4 -loop 0 bun/*.jpg bun.gif
2012-01-05 17:53:22
User: joeyliechty
0

Creates a better looking gif than the original post via imagemagick processing high quality jpgs, rather than converting directly to gif from the video itself.

python -c 'print "hello".encode("hex")'
2011-12-13 23:05:17
User: atoponce
Functions: python
2

You can use "decode()" in a similar manner:

python -c 'print "68656c6c6f".decode("hex")'
evince-thumbnailer --size=600 book.pdf book.png
convert -resize 200 awk.pdf[0] awk.png
mencoder vcd://2 -o sample.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4
tr -d "\r" < file.vcf | tr "\0" " " > file.vcf.txt
convert -background none -pointsize 55 label:"`whoami`" me.png
2011-09-07 17:06:38
User: totti
1

Create transparent image to use as icon, watermark for other images, etc.

sox is_that_correct.wav -t raw -r 8000 -s -w -c 1 is_that_correct.sln
sudo sox <file name>.wav -r 8000 <file name>.gsm
sudo sox <file name>.wav -r 8000 <file name>.gsm
xxd -p <<< <STRING>
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
xml2asc < inputfile > outputfile
2011-02-23 12:22:18
User: forcefsck
-3

For reverse, there's asc2xml

asc2xml < entitiesfile > utf8file

They come as a part of the html-xml-utils debian package.

PS. Tried to submit sample data, but the site autoconverted the non ascii to html entities. So a bit of imagination is needed.

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.

lame rec01.wav rec01.mp3
mencoder -idx a.ogg -ovc lavc -oac mp3lame -o b.avi
for i in $(ls *.flv); do ffmpeg2theora -v 6 --optimize $i; done
2010-12-01 14:13:31
User: joenjeru
Functions: ls
0

Do you have a large library of flv's you have picked up over the years using FlashGot Firefox plugin?

Do you want to be able to convert them to Ogg Theora (video) at once?

Try out this script...

mogrify -trim *png
2010-10-21 15:09:33
User: houghi
Tags: convert png trim
1

That should be a short as it can get.

for file in *.png; do mogrify -trim "$file"; done
for file in `ls *.png`; do convert -trim $file $file; done
for f in *;do flac -cd $f |lame -b 192 - $f.mp3;done
convert -density 300 input.pdf -fill "rgb(255,255,255)" -opaque "rgb(0,0,0)" output.pdf
2010-10-07 17:24:19
User: akrog
Tags: pdf print convert
2

The pdf is first converted to a bitmap, so change "-density" to match your printer resolution. Also be careful about the RAM required.

In this example rgb(0,0,0) is replaced by rgb(255,255,255), change to suit your needs.

for file in *.jpg; do convert "$file" -resize 800000@ -quality 80 "small.$file"; done
2010-09-13 19:06:14
User: grinob
Functions: file
Tags: xargs convert
8

Convert all jpegs in the current directory into ~1024*768 pixels and ~ 150 KBytes jpegs