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,860 results
ls !$
2009-04-07 12:31:06
Functions: ls
1

Suppose that you had change in a directory like /home/user/mycode/code, and now you need to list it, instead of type entire path again, use ls !$ to recall path and list. Useful with many commands, this is only an example. (In this case, same result can be achivied with ls .)

sed -i.bak '/^[[:space:]]*$/d' file_name
2009-04-07 11:32:06
User: Highwayman
Functions: sed
0

Remove blank lines from files, even if some of the lines have whitespace (spaces, tabs, etc.). Also creates a .bak copy of the original file. Works on Mac also.

Thanks to those all those who left comments.

for file in $(find -type f -iname "*wav"); do mv $file "$file"_orig.WAV; mplayer -ao pcm "$file"_orig.WAV -ao pcm:file=$file; done
vi `!!`
2009-04-06 17:58:13
User: vimes656
Functions: vi
4

That will open vi with the four README files in different viewports.

Specially handy when you find there is only one file matching your pattern and you don't want to specify the full path.

alias backup_dir='mkdir -p .backup && cp * .backup'
2009-04-06 14:43:21
User: k00pa
Functions: alias cp
-3

Add this to .bashrc, then you can quickly create backups from files on current directory, but it only backups files on current directory.

useful when changing config files, coding something or just trying something stupid.

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.