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,484 results
curl -u username -o bookmarks.xml https://api.del.icio.us/v1/posts/all
sudo -i
grep "install " /var/log/dpkg.log | awk '{print $4}' | xargs apt-get -y remove --purge
command > tmp && cat logfile.txt >> tmp && tmp > logfile.txt && rm tmp
2009-04-05 22:00:32
User: akoumjian
Functions: cat command rm
-2

Adds the stdout (standard output) to the beginning of logfile.txt. Change "command" to whatever command you like, such as 'ls' or 'date', etc. It does this by adding the output to a temporary file, then adding the previous contents of logfile.txt to the temp file, then copying the new contents back to the logfile.txt and removing the temp file.

history|awk '{print $2}'|awk 'BEGIN {FS="|"} {print $1}'|sort|uniq -c|sort -r
2009-04-05 13:40:56
User: kayowas
Functions: awk sort uniq
7

It will return a ranked list of your most commonly-entered commands using your command history

rm -r .??*
2009-04-05 09:19:26
Functions: rm
3

Remove all hidden files in a directory excluding current dir . and parent dir .. with .??* that means files with at least two characters.

shuf -n1 /usr/share/dict/words | tee >(sed -e 's/./&\n/g' | shuf | tr -d '\n' | line) > /tmp/out
find . \( -type d -name .svn -prune \) -o -print | while read file ; do mergeinfo=`svn propget svn:mergeinfo $file` ; [ "$mergeinfo" != "" ] && echo -e "$file\n $mergeinfo\n" ; done
svn propset svn:ignore "*txt" log/
2009-04-04 23:09:01
Tags: svn
5

If you don't want to commit files to subversion, and don't want those file to show up when doing an "svn stat", this command is what you need

< /dev/urandom tr -dc A-Za-z0-9_ | head -c $((1024 * 1024)) | tee >(gzip -c > out.gz) >(bzip2 -c > out.bz) > /dev/null
sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E "Host\: .*|GET \/.*"
2009-04-04 01:41:48
User: peterc
Functions: grep sudo tcpdump
-2

Replace "en1" with your network interface (on OS X, usually en0, en1, eth0, etc..)

diff <(ssh alice cat /etc/apt/sources.list) <(ssh bob cat /etc/apt/sources.list)
/usr/local/bin/svn merge -r {rev_num}:HEAD https://{host}/{project}/branches/{branch_name} .
2009-04-03 15:43:32
User: kamiller
Functions: merge
Tags: svn merge
1

This will merge all of the changes from {rev_num} to head on the branch to the current working directory

identify -ping imageName.png
rm -rf `find ./ -iname *.svn*`
dmesg | grep cpu
2009-04-03 01:57:04
User: kingji
Functions: dmesg grep
Tags: cpus
-16

get cpu info from dmesg

history | grep ssh
2009-04-03 01:35:52
User: haivu
Functions: grep
Tags: bash csh
-9

After seeing the command you wish to repeat, just invoke it using the ! syntax.

ncal -e
2009-04-02 17:58:27
Tags: ncal dates
4

ncal -e shows the date of Easter this year. ncal -e YYYY shows the date of Easter in a given year. ncal -o works the same way, but for Orthodox dates.

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

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.

cal -3
2009-04-02 17:40:38
User: haivu
Functions: cal
Tags: PIM
-3

the -3 show the previous, current, and next month.

whatis [command-name]
2009-04-02 17:30:13
User: haivu
Functions: whatis
5

The whatis command displays a short description for the command you list on the command line. It is useful to quickly learn what a command does

sudo vi /etc/fstab; Go//smb-share/gino /mnt/place smbfs defaults,username=gino,password=pass 0 0<esc>:wq; mount //smb-share/gino
2009-04-02 16:04:35
User: GinoMan2440
Functions: mount sudo vi
4

the middle command between the ; and ; is the vi commands that insert that line into the last line of the file, the esc with the carets is literally hitting the escape key, you have to have the smbfs package installed to do it, I use it to access my iTunes music on my mac from my linux PC's with amarok so I can play the music anywhere in the house. among other things, it allows you to access the files on that share from your computer anytime you're on that network.

save_state=$(stty -g);echo -n "Password: ";stty -echo;read password;stty "$save_state";echo "";echo "You inserted $password as password"
2009-04-02 15:57:05
User: acirulli
Functions: stty
5

Allow to read password in a script without showing the password inserted by the user

find . -type f -size +25000k -exec ls -lh {} \; | awk '{ print $8 ": " $5 }'
dstat -ta