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,491 results
info --vi-keys
2009-04-11 22:10:08
User: kFiddle
Functions: info
7

Info has some of the worst keybindings I've ever seen. Being a vim user, I attribute that to emacs influence. Use the --vi-keys option to use some of the vi keybindings, although this won't change all the keybindings. Use the "infokey" program to have more control over info keybindings.

\bTERM\b
2009-04-11 22:05:12
User: kFiddle
Tags: less regex
5

Although less behaves more or less like vim in certain aspects, the vim regex for word boundaries (\< and \>) do not work in less. Instead, use \b to denote a word boundary. Therefore, if you want to search for, say, the word "exit", but do not want to search for exiting, exits, etc., then surround "exit" with \b. This is useful if you need to search for specific occurrences of a keyword or command. \b can also be used at just the beginning and end, if needed.

sudo killall -9 pulseaudio; pulseaudio >/dev/null 2>&1 &
2009-04-11 20:18:35
User: hank
Functions: killall sudo
15

Ever since the switch to pulseaudio, Ubuntu users including myself have found themselves with no sound intermittently. To fix this, just use this command and restarts firefox or mplayer or whatever.

find ~ -mtime +365 -exec mv {} /tmp/mybackup \;
2009-04-11 12:16:48
User: kayowas
Functions: find mv
-5

This example uses the -exec option to move all matching files into a backup directory

$ perl -pi -e 's/\r\n/\n/g' <finelame>
2009-04-10 22:22:31
Functions: perl
Tags: perl dos2unix
0

Converts windows lined-style file to unix.

see http://en.wikipedia.org/wiki/Newline

Can be used to convert from linux2dos : just invert \r\n and \n.

svn status | grep '^?' | awk '{ print $2; }' | xargs svn add
2009-04-10 21:55:37
Functions: awk grep xargs
Tags: svn awk xargs
1

Lists the local files that are not present in the remote repository (lines beginning with ?)

and add them.

tar -czvvf backup$(date "+%Y%m%d_%H%M%S").tar.gz /path/to/dir
2009-04-10 21:37:17
Functions: date tar
5

creates a tar.gz with a name like:

backup20090410_173053.tar.gz

of a given directory.

this file was made 10 April 2009 at 5:30:53pm

see date's man page to customize the timestamp format

identify -verbose *.jpg|grep "\(Image:\|Resolution\)"
curl dict://dict.org/d:something
2009-04-10 18:12:37
Tags: curl
15

A bash function might also be useful:

dict() { curl dict://dict.org/d:$1; }

Or if you want less verbose output:

dict() { curl -s dict://dict.org/d:$1 | perl -ne 's/\r//; last if /^\.$/; print if /^151/../^250/'; }
#!/bin/sh #du.sh i=`hostname -i` df -h > /tmp/space.txt echo "server $i " >> /tmp/space.txt uuencode /tmp/space.txt space.txt | mail -s "HDD usage $i" email@email.com
#!/bin/sh for dir in `ls -A | grep -v .sh`; do chown -R $dir:$dir $dir done
function jumpTo { xmms2 jump `xmms2 list | grep -i '$1' | head -n 1 | tail -n 1 | sed -re 's@.+\[(.+)/.+\] (.+)@\1@'`; }
2009-04-10 13:43:57
User: pyrho
Functions: grep head sed tail
Tags: xmms2
1

Usage:

Declare this function in your Shell, then use it like this:

> jumpTo foo

The script will search for the 'foo' pattern in your current xmms2 playlist (artist or songname), and play the first occurence of it !

disown -a && exit
for f in * ; do mv -- "$f" "${f/[0-9][0-9] \- /}" ; done
2009-04-10 11:06:13
Functions: mv
-4

I have often file like this

01 - file.file

02 - file.file

03 - file.file

I rename all with this command

for f in * ; do mv -- "$f" "${f/[0-9][0-9] \- /}" ; done

then it looks like this

file.file

file.file

file.file

etc

mtr --report --report-cycles 10 www.google.com > google_net_report.txt
2009-04-10 07:57:44
User: CafeNinja
Tags: Network
7

The report mode of mtr produces a text formated result of the mtr run using the number of ping cycles stated by the command. This text file could then be attached to an email with ease.

I use this also without the ">" portion when writing email from within mutt using VI from the command mode with ":r !mtr --report --report-cycles 10

svn info | grep '^URL:' | egrep -o '(tags|branches)/[^/]+|trunk' | egrep -o '[^/]+$'
2009-04-09 20:08:45
User: isaacs
Functions: egrep grep info
Tags: svn grep
1

Get the svn info, grep for the "URL" of the repository, pull out the tag/branch/trunk, and then just show the helpful/meaningful bit.

sudo update-alternatives --config editor
2009-04-09 18:26:52
User: mheadd
Functions: sudo
2

On Ubuntu, the default editor for visudo is nano. To change the editor to something else (e.g., vi) use this command.

grep -r "mystring" . |uniq | cut -d: -f1 | xargs sed -i "s/mystring//"
2009-04-09 12:49:01
Functions: cut grep sed uniq xargs
-3

Linux : these script enable you to edit multiple files and remove exact phrase from multiple files

kill %1
stat -c '%A %a %n' *
2009-04-09 10:44:56
Functions: stat
22

Nicely display permissions in octal format and filename for a given directory

mplayer -vo dummy -ao dummy -identify your_video.avi
trap cmd 0
2009-04-08 21:34:13
Functions: trap
7

Execute a command on shell logout,and run it until is finished,then shell is closed.

:<C-R><C-W>
2009-04-08 21:25:06
User: pyrho
Tags: vim
31

Very handy to bring the word currently under the cursor into a :s command in Vim.

Example:

If the cursor was on the word "eggs":

:s/ ==> :s/eggs

tar --exclude='.svn' -c -f /path/to/file.tar /path/to/directory
dd if=/dev/urandom of=file.img bs=4KB& pid=$!
2009-04-08 05:56:47
User: atoponce
Functions: dd
9

Running this code will execute dd in the background, and you'll grab the process ID with '$!' and assign it to the 'pid' variable. Now, you can watch the progress with the following:

while true; do kill -USR1 $pid && sleep 1 && clear; done

The important thing to grasp here isn't the filename or location of your input or output, or even the block size for that matter, but the fact that you can keep an eye on 'dd' as it's running to see where you are at during its execution.