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

All commands from sorted by
Terminal - All commands - 11,621 results
'ls -1 *<pattern>* | while read file; do scp $file user@host:/path/; if [[ $? -eq 0 ]]; then rm $file; fi; done'
ct mkelem -nc `find ./ -name "*" | xargs`
cleartool co -nc `cleartool ls -recurse | grep "hijacked" | sed s/\@\@.*// | xargs`
locate searchstring | xargs ls -l
kadmin -p admin@NOC.NBIRN.NET -q "ktadd -k /etc/krb5.keytab host/hostname"
kadmin -p admin@NOC.NBIRN.NET -q "addprinc -randkey host/host"
set -o vi; ls -l jnuk<ESC>bCjunk
2009-02-05 22:58:51
User: jonty
Functions: ls set
1

If you spend all day editing in vi then switching your fingers to Emacs mode just for the command line can be difficult. Use set -o vi in your bash shell and enjoy the power of a real editor.

sudo netstat -punta
screen -xR
2009-02-05 22:22:10
User: stuart
Functions: screen
4

Have your screen session running in multiple places. (warning, things start to look weird if the terminal windows have different dimensions)

myLongScript && echo -e '\a' || (echo -e '\a'; sleep 1; echo -e '\a')
2009-02-05 22:13:43
User: stuart
Functions: echo sleep
1

This will ring the system bell once if your script exits successfully and twice if it fails. So you can go look at something else and it will alert you when done. Don't forget to use 'xset b [vol [pitch [duration]]]' to get the bell to sound the way you want.

pkill -U MYWIFE
2009-02-05 22:10:07
User: HansReiser
-2

Kills all processes owned by user MYWIFE (replace MYWIFE with username or ID of your choice)

(Thanks, porges, for the better command)

tr -dc '[:print:]' < /dev/urandom
2009-02-05 21:51:14
User: gracenotes
Functions: tr
4

Reads psuedorandom bytes from /dev/urandom, filtering out non-printable ones. Other character classes can be used, such as [:alpha:], [:digit:] and [:alnum:]. To get a string of 10 lowercase letters:

tr -dc '[:lower:]' < /dev/urandom | head -c 10
^u
2009-02-05 21:37:46
User: zgomot
6

Type ^u at password prompt to clear a mistyped password.

(on destination machine) nc -l 1234 > whatever; (on source machine) nc destination 1234 < whatever;
2009-02-05 21:35:08
User: jonty
3

Einstein's razor: As simple as possible, but not simpler.

On the destination machine netcat listens on any port (1234 in the example) and sends anything it receives into a file or pipe. On the source machine a separate netcat takes input from a file or pipe and sends it over the network to the listener.

This is great between machines on a LAN where you don't care about authentication, encryption, or compression and I would recommend it for being simpler than anything else in this situation. Over the internet you should use something with better security.

dig foo.org mx +short
cd ~/.purple/logs/; egrep -ri "i can haz|pwn|l33t|w00|zomg" * | cut -d'/' -f 3 | sort | uniq | xargs -I {} echo "Note to self: ban user '{}'"
jstat -gc [jvmpid]
tidy -xml -i -m [file]
2009-02-05 21:22:33
User: scw
27

Generated XML files often are poorly formatted. Use this command to properly indent and normalize the file in-place.

cvs -Q status | grep -i locally
dos2unix dostxt unixtxt
2009-02-05 21:11:43
User: wwest4
0

converts non-ISO dos text files for use on unix systems.

touch -acm yyyymmddhhMM.ss [file]
2009-02-05 21:07:09
User: wwest4
Functions: touch
0

...changes modify time and access time. also:

touch -r [file1] [file2] # make file2 timestamp match file1

tar cfvz - /home/user | netcat -l -p 10000
2009-02-05 21:05:40
User: ajrobinson
Functions: tar
1

tar's directory and sends to netcat listening on port 10000

On the client end:

netcat [server ip] 10000 | tar xfvz -

This will send it over the network and extract it on the clients machine.

ldconfig -p
2009-02-05 21:02:59
User: wwest4
Functions: ldconfig
3

shows which shared lib files are pointed to by the dynamic linker.

echo "import random; print(random.choice(['heads', 'tails']))" | python
export SSH_AUTH_SOCK=`find /tmp/ssh* -type s -user [user] -mtime -1 | head -1`
2009-02-05 20:55:41
User: wwest4
Functions: export head
1

Must be done as root - will cause subsequent ssh connections to use the identities available via the [user]'s agent socket.