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
ls *.JPG | cut -d . -f 1 | xargs -L1 -i convert -resize 684 {}.JPG {}.jpg
recode -l |less
2010-08-19 17:35:23
User: vlan7
Tags: convert
1

aliases on each line.

i.e.

txt2html:

recode ..HTML <file.txt >file.html

txt to Base64:

recode ../b64 <file.txt >file.b64

and so on.

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

convert example.png -resize 100x100! output.png
2010-08-08 17:29:36
User: karpoke
Tags: convert
1

Adding the exclamation mark to the image geometry ignores the original aspect ratio.

More info about image geometry:

http://www.imagemagick.org/script/command-line-processing.php#geometry

convert example.png -resize 100x100 output.png
2010-08-08 16:40:21
User: dbbolton
-1

You can also specify width and height of the resized image (in pixels), as an alternative to using a percentage.

convert -quality 40% original_image reduced_image
utime(){ python -c "import time; print(time.strftime('%a %b %d %H:%M:%S %Y', time.localtime($1)))"; }
utime(){ awk -v d=$1 'BEGIN{print strftime("%a %b %d %H:%M:%S %Y", d)}'; }
utime(){ date -d "1970-01-01 GMT $1 seconds"; }
utime { date -d @$1; }
2010-05-12 12:21:15
User: deltaray
Functions: date
4

More recent versions of the date command finally have the ability to decode the unix epoch time into a human readable date. This function makes it simple to utilize this feature quickly.

ffmpeg -i input.avi -s qcif -vcodec h263 -r 20 -b 180k -acodec libfaac -ab 64k -ac 2 -ar 22050 output.3gp
2010-04-24 23:01:21
User: mariusbutuc
3

ffmpeg

-i = input file name

-s = set frame size, qcif=176x144

-vcodec = force video codec

-r = frame-rate [default = 25]

-b = bit-rate [200 kb/s]

-acodec = force audio codec

-ab = audio bitrate in bits/s [64k]

-ac = no. of audio channels [1]

-ar = audio sampling frequency [44100 Hz]

optional:

-sameq = use same video quality as source (implies VBR)

-f = force format

-y = overwrite output files

echo $ascii | perl -ne 'printf "%x", ord for split //'
echo $ascii | perl -ne 'printf ("%x", ord($1)) while(/(.)/g); print "\n";'
echo $hex | perl -pe 's/(..)/chr(hex($1))/ge'
pv -cN orig < foo.tar.bz2 | bzcat | pv -cN bzcat | gzip -9 | pv -cN gzip > foo.tar.gz
2010-04-16 05:21:10
User: rkulla
Functions: gzip
0

In this example we convert a .tar.bz2 file to a .tar.gz file.

If you don't have Pipe Viewer, you'll have to download it via apt-get install pv, etc.

for file in *.flac; do flac -cd "$file" | lame -q 0 --vbr-new -V 0 - "${file%.flac}.mp3"; done
convert in.pdf out.jpg
utime(){ perl -e "print localtime($1).\"\n\"";}
2009-11-06 12:58:10
User: MoHaG
Functions: perl
1

A shell function using perl to easily convert Unix-time to text.

Put in in your ~/.bashrc or equivalent.

Tested on Linux / Solaris Bourne, bash and zsh. using perl 5.6 and higher.

(Does not require GNU date like some other commands)

ffmpeg -i input.mov -b 4096k -vcodec msmpeg4v2 -acodec pcm_u8 output.avi
2009-10-21 05:44:31
User: oracular
1

Convert those .mov files that your digital camera makes to .avi

Adjust the bitrate (-b) to get the appropriate file size. A larger bitrate produces a larger (higher quality) .avi file and smaller bitrate produces a smaller (lower quality) .avi file.

Requires ffmpeg (see man page for details)

(tested with canon camera MOV files)

Other examples:

ffmpeg -i input.mov -sameq -vcodec msmpeg4v2 -acodec pcm_u8 output.avi ffmpeg -i input.mov -b 1024k -vcodec msmpeg4v2 -acodec pcm_u8 output.avi
chr () { echo -en "\0$(printf %x $1)"}
chr() { printf \\$(printf %o $1); }
chr () { printf \\$(($1/64*100+$1%64/8*10+$1%8)); }
2009-10-15 07:01:54
User: dennisw
Functions: printf
5

I've corrected the function. My octal conversion formula was completely wrong. Thanks to pgas at http://mywiki.wooledge.org/BashFAQ/071 for setting me straight. The new function is from pgas and is very fast.

ffmpeg -i inputfile.mp4 outputfile.flv
2009-09-10 14:49:14
Tags: ffmpeg convert
6

This converts any media ffmpeg handles to flash. It would actually convert anything to anything, it's based on the file extension. It doesn't do ANY quality control, sizing, etc, it just does what it thinks is best. I needed an flv for testing, and this spits one out easily.

dos2unix file.txt
:%s/^V^M//g
2009-08-19 11:59:22
User: slim
-1

Whereas ^V is CTRL-V.

converts a dos file to unix by removing 0x13 characters