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.


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:



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.




All commands from sorted by
Terminal - All commands - 11,488 results
Printing portion of a big file
2009-03-30 11:08:38
User: acirulli
Tags: sed

If you need to print some portion of a huge file, let's say you want to print from line 200 to 300, you can use this command to print the line from LINE1 to LINE2 of file FILE.

shred -v filename
dd if=/dev/urandom of=/dev/speaker bs=1
2010-10-27 09:22:40
User: khashmeshab
Functions: dd

Sends random beeps to your PC-speaker. Think... You can also run it remotely on another computer using SSH and scare its user! Don't forget to run it on your dedicated hosting server and watch sysadmin's action from data-center's live remote cameras!

awk 'END {print NR}' /etc/passwd
dd if=/dev/urandom of=/dev/dsp
2010-10-27 09:25:02
User: khashmeshab
Functions: dd

Sends random sounds to your sound card output (e.g. your speaker). Think... You can also run it remotely on another computer using SSH and scare its user!

echo 1+1|bc
x=; whois $x > $x.txt
2011-01-17 03:33:49
User: sxiii
Functions: whois

This can be used in scripts, to find out the origin of target IP etc.

echo -en "$USER@$HOSTNAME:${PWD##*/}> ";while read x;do echo $x>>/tmp/log.txt;echo $x|$0 2>&1;echo -en "$USER@$HOSTNAME:${PWD##*/}> ";done
export var1=`ps -A | grep '[u]nique' | cut -d '?' -f 1`; echo${var1/ /}; kill -9 $var1
2010-03-22 21:06:58
User: headyadmin
Functions: cut export grep kill
Tags: Os X

This will kill a specific process you don't know the PID of, when pidof and pgrep are not available, for example on OS X. var1 is created so that the whitespace can be trimmed before passing off to kill.

join file1.txt file2.txt > file3.txt
apt-get search something | grep specific
2010-09-27 07:10:39
User: ProfOak
Functions: apt grep

replace apt-get with your distro's package manager.

Where 'something' is the package name, and 'specific' is what you're specifically looking for.

This helps if your query is 2+ words long.

grep -A 3 -i "example" demo_text
python -c "import socket; print '\n'.join(socket.gethostbyname_ex(socket.gethostname())[2])"
2009-04-30 16:10:43
User: haivu
Functions: python
Tags: Network python

The socket.gethostname() call returns the host name of the computer. The socket.gethostbyname_ex() call returns a list of three items: The host name, the list of aliases for this host, and a list of IP addresses. Recall that Python?s array starts with index 0, the socket.gethostbyname_ex(?)[2] expression refers to the list of IP addresses. Finally, the print statement prints out the IP addresses, one per line.

curl whatismyip.org
nawk '{line[NR]=$0} END{for (; NR>=1; NR--){print line[NR]}}' FILENAME
sudo dmesg
for i in $(file * | grep broken | cut -d : -f 1); do rm $i; done
scp -P 22 /home/svnlabs.txt root@
2010-01-22 16:55:25
User: svnlabs
Functions: scp

Upload file to remote server using SCP

telnet zerocarbs.wooters.us
find ~/Desktop/ \( -regex '.*/\..*' \) -print -exec rm -Rf {} \;
watch -n 1 uptime\;myqladmin --user=<user> --password=<password> --verbose processlist
2009-03-21 18:29:28
User: root
Functions: watch
Tags: mysql

Useful for monitoring both MySQL and the server load at the same time.

ps -ef | grep [j]boss | awk '{print $2}'|xargs kill -9
2010-09-30 15:55:41
User: utoxin
Functions: awk grep kill ps xargs
Tags: kill

Removed unneeded grep -v by making the initial grep unable to match itself.

find Documents\ and\ Settings -iregex .+\.doc -or -iregex .+\.xls > office.lst
2010-11-04 17:58:52
User: yababay
Functions: find

This command is useful for archiving or extracting Documents and Settings folder, when working in Linux box with Windows partition (dual boot installation). You have to enter into appropriate directory, of course.

ls -l | grep ^l
2009-04-02 17:47:36
User: haivu
Functions: grep ls
Tags: ls

Shows all linked file and destinations. The 'ls -l' command lists the files in long (1 file per line) format, and the grep command displays only those lines that starts with an l (lower case L) -- a linked file.

Updated: Remove reference to hard links because this command does not apply to hard link as others kindly pointed out.