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 by sudopeople from sorted by
Terminal - Commands by sudopeople - 9 results
cat part1.avi part2.avi part3.avi > tmp.avi && mencoder -forceidx -oac copy -ovc copy tmp.avi -o output.avi && rm -f tmp.avi
2013-09-05 01:47:22
User: sudopeople
Functions: cat rm
4

Useful for when you download movies split into < 700mb parts.

Credit to rich @ http://superuser.com/questions/318640/merge-avi-files-without-recoding-in-mac-os-x-lion

mencoder is generally included with mplayer.

MacPorts:

sudo port install mplayer
for i in */; do echo tar -cjf "${i%/}.tar.bz2" "$i"; done
2013-08-20 22:13:28
User: sudopeople
Functions: echo tar
1

Remove the "echo" to actually archive.

Many similar commands are found on commandlinefu but I end up needing this very specific one from time to time.

To extract any of them, use the standard tar.bz2 extract command:

tar xvjf folder1.tar.bz2
apt-cache search php5
2012-09-20 21:14:50
User: sudopeople
Functions: apt
-9

Can't remember what that one package was called? Search for it!

It's also a good idea to run

apt-get update

first.

ufraw-batch --out-type=jpeg --out-path=./jpg ./*.NEF
2009-04-15 09:03:59
User: sudopeople
Tags: photo photos
6

converts RAW files from a Nikon DSLR to jpg for easy viewing etc.

requires ufraw package

while true; do [ "$(ping -c1W1w1 server-or-ip.com | awk '/received/ {print $4}')" != 1 ] && beep; sleep 1; done
2009-03-31 20:47:56
User: sudopeople
Functions: sleep
14

pings a server once per second, and beeps when the server is unreachable.

Basically the opposite of:

ping -a server-or-ip.com

which would beep when a server IS reachable.

You could also substitute beep with any command, which makes this a powerful alternative to ping -a:

while true; do [ "$(ping -c1W1w1 server-or-ip.com 2>/dev/null | awk '/received/ {print $4}')" = 1 ] && date || echo 'server is down!'; sleep 1; done

which would output the date and time every sec until the ping failed, in which case it would echo.

Notes:

Requires beep package.

May need to run as root (beep uses the system speaker)

Tested on Ubuntu which doesn't have beep out of the box...

sudo apt-get install beep
echo '!'whammy
2009-03-26 23:34:33
User: sudopeople
Functions: echo
Tags: literal bang
-3

Seems obvious, but other seemingly simple ways to use it don't work:

echo !whammy

and

echo "!whammy"

both output:

-bash: !whammy: event not found

and this:

echo "\!whammy"

outputs:

\!whammy

with the slash :(

you can also do any combinations of quotes for a complex string:

echo "It's great to be able to use a bang ("'!'") in a command"'!'

outputs:

It's great to be able to use a bang (!) in a command!
php -r 'echo strtotime("2009/02/13 15:31:30")."\n";'
2009-03-24 19:38:46
User: sudopeople
7

Most people know that you can run a PHP script from the command line like so:

php ./my_script.php

But sometimes I just want to run a quick bit of code, the PHP Command Line Interface allows me to do so with the -r option.

Requires package php5-cli

rsync -vazuK --exclude "*.mp3" --exclude "*.svn*" * user@host:/path
2009-02-27 19:58:02
User: sudopeople
Functions: rsync
Tags: svn exclude
2

rsyncs files to a server excluding listed files

also a file can be used to exclude common exclude rules and/or to exclude a ton of files, like so:

rsync --exclude-from '~/.scripts/exclude.txt'

where exclude.txt has one rule per line:

*.mp3

*.svn*

cat /etc/*-release
2009-02-26 08:22:01
User: sudopeople
Functions: cat
10

Works for most distributions, tested on Ubuntu, Fedora, CentOS, Gentoo, SUSE, RedHat.

Debian and Slackware:

cat /etc/*version