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,583 results
wget -q -O - "$@" <url>
echo "12345,12346" |sed -e's/ //'|tr "," "\n"| while read line; do echo -n $line" "; svn log -vr $line https://url/to/svn/repository/|grep "/"|head -1|cut -d"/" -f2; done
date -r foo
ufraw-batch --out-type=jpeg --out-path=./jpg ./*.NEF
2009-04-15 09:03:59
User: sudopeople
Tags: photo photos
6

converts RAW files from a Nikon DSLR to jpg for easy viewing etc.

requires ufraw package

sudo cat /dev/vcs1 | fold -w 80
2009-04-15 08:49:48
User: animoid
Functions: cat fold sudo
16

This will view the console and assumes the screen is 80 characters wide.

Use /dev/vcs2 for the next virtual console.. etc.

/sbin/ifconfig -a | awk '/(cast)/ { print $2 }' | cut -d':' -f2 | head -1
echo 'wget url' | at 12:00
convert images*.* <my_pdf>.pdf
watch "dmesg |tail -15"
2009-04-14 03:13:17
User: Buzzcp
Functions: watch
11

Other logs can be monitored similarly, e.g.

watch "tail -15 /var/log/daemon.log"
find | sed -e "s/^.*\///" | awk ' BEGIN { FS=""} { print NF " " $0 } ' | sort -nrf | head -10
watch -n 1 "netstat -tpanl | grep ESTABLISHED"
ls -la
cd ~/.mozilla/firefox/ && sqlite3 `cat profiles.ini | grep Path | awk -F= '{print $2}'`/formhistory.sqlite "select * from moz_formhistory" && cd - > /dev/null
2009-04-13 20:23:37
User: klipz
Functions: awk cd grep
19

When you fill a formular with Firefox, you see things you entered in previous formulars with same field names. This command list everything Firefox has registered. Using a "delete from", you can remove anoying Google queries, for example ;-)

svn status | grep "^\?" | awk '{print $2}' | xargs svn add
yum erase `yum list installed | grep 'php'`
2009-04-13 12:58:16
Functions: grep
-4

This is useful for remove all packages that are part of a common suite.

i=10;for o in *.mp3; do i=$(printf "%02d" $i); mv $o $i$o; ((i = $i + 2)); done
2009-04-13 12:33:52
User: bazzawill
Functions: mv printf
-1

This command adds the numbers 10, 12, 14 to a bunch of mp3's in the current working directory. You can then run the command replacing the inital i=10 with i=11 to add 11,13,15 in another directory then mv the files together and the first files interweave with the second group of files. I used this to weave a backlog of a podcast with other podcast so I didn't get sick of one while I was catching up. I started at 10 because printf blows up with 0 padded numbers 08 and 09 which kind of makes the printf command redundant as it was used to pad numbers 1 - 9 so they would come first and not get sorted incorrectly

alias lg='ls --color=always | grep --color=always -i'
2009-04-11 23:15:12
User: kFiddle
Functions: alias grep
Tags: ls alias color grep
6

This is a simple command, but extremely useful. It's a quick way to search the file names in the current directory for a substring. Normally people use "ls *term*" but that requires the stars and is not case insensitive. Color (for both ls and grep) is an added bonus.

function v { if [ -z $1 ]; then vim; else vim *$1*; fi }
2009-04-11 23:06:43
User: kFiddle
Functions: vim
Tags: vim vi function
0

Reduce the number of keystrokes it takes to open a file in vim. First of all, you just need to type "v", which is less than half the number of characters (!), and second-of-all, you only need to enter a substring of the file you want to open. For example, if you want to open the file, homework.txt, then type "v hom" to open it. Good tip is to use the lowest unique substring, otherwise you'll open multiple files in different buffers (which is sometimes desirable). Use Ctrl-^ to switch between buffers.

date -d@1234567890
2009-04-11 22:26:41
User: kFiddle
Functions: date
Tags: date
44

This example, for example, produces the output, "Fri Feb 13 15:26:30 EST 2009"

find -writable
2009-04-11 22:16:35
User: kFiddle
Functions: find
4

Have a grudge against someone on your network? Do a "find -writable" in their directory and see what you can vandalize! But seriously, this is really useful to check the files in your own home directory to make sure they can't inadvertently be changed by someone else's wayward script.

info --vi-keys
2009-04-11 22:10:08
User: kFiddle
Functions: info
8

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
14

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.