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,616 results
ps -eo user,pcpu,pmem | tail -n +2 | awk '{num[$1]++; cpu[$1] += $2; mem[$1] += $3} END{printf("NPROC\tUSER\tCPU\tMEM\n"); for (user in cpu) printf("%d\t%s\t%.2f%\t%.2f%\n",num[user], user, cpu[user], mem[user]) }'
alias xdef_load='xrdb -merge ~/.Xdefaults'
2009-05-05 16:34:06
User: P17
Functions: alias
0

Reads in the ~/.Xdefaults lexicographically sorted with, instead of replacing, the current contents of the specified properties.

alias b='cd -'
shopt -s globstar
2009-05-05 16:02:44
User: Alanceil
11

Since bash 4.0, you can use ** to recursively expand to all files in the current directory. This behaviour is disabled by default, this command enables it (you'd best put it in your .profile). See the sample output for clarification.

In my opinion this is much better than creating hacks with find and xargs when you want to pass files to an application.

VBoxManage startvm "name"
sed -i '/Centos/d' VirtualBox.xml
2009-05-05 13:03:55
Functions: sed
-3

Simple but useful command, I use this for purge an hard disk entry in Virtualbox registry file (is in ~user/.Virtualbox) that persist if I erase a Virtual Machine, so I need to delete it manually.

alias somafm='read -p "Which station? "; mplayer --reallyquiet -vo none -ao sdl http://somafm.com/startstream=${REPLY}.pls'
2009-05-05 12:13:46
User: denzuko
Functions: alias
-2

This is the alias command that I discussed in my prior release which you can add to your ~/.bashrc.

This command asks for the station name and then connects to somafm, Great for those who have linux home entertainment boxes and ssh enabled on them, just for the CLI fiends out there ( I know I'm one of them ;)

You can find future releases of this and many more scripts at the teachings of master denzuko - denzuko.co.cc.

lynx -dump randomfunfacts.com | grep -A 3 U | sed 1D
2009-05-05 07:52:10
User: xizdaqrian
Functions: grep sed
0

This is a working version, though probably clumsy, of the script submitted by felix001. This works on ubuntu and CygWin. This would be great as a bash function, defined in .bashrc. Additionally it would work as a script put in the path.

wget -q -O- http://www.gutenberg.org/dirs/etext96/cprfd10.txt | sed '1,419d' | tr "\n" " " | tr " " "\n" | perl -lpe 's/\W//g;$_=lc($_)' | grep "^[a-z]" | awk 'length > 1' | sort | uniq -c | awk '{print $2"\t"$1}'
2009-05-04 16:00:39
User: alperyilmaz
Functions: awk grep perl sed sort tr uniq wget
-4

This command might not be useful for most of us, I just wanted to share it to show power of command line.

Download simple text version of novel David Copperfield from Poject Gutenberg and then generate a single column of words after which occurences of each word is counted by sort | uniq -c combination.

This command removes numbers and single characters from count. I'm sure you can write a shorter version.

for file in <directory A>/*; do rm <directory B>/`basename $file`; done
2009-05-04 12:44:50
User: jamiebullock
Functions: file rm
Tags: delete rm
10

This command is useful if you accidentally untar or unzip an archive in a directory and you want to automatically remove the files. Just untar the files again in a subdirectory and then run the above command e.g.

for file in ~/Desktop/temp/*; do rm ~/Desktop/`basename $file`; done
curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=csco&f=l1'
2009-05-04 08:13:59
User: haivu
Tags: curl finance
11

Retrieve the current stock price from Yahoo Finance. The output is simply the latest price (which could be delayed). If you want to look up stock for a different company, replace csco with your symbol.

nl filename | more
2009-05-04 07:35:16
User: haivu
Functions: nl
-2

The nl command lists the contents of a file where is each line is prefixed by a line number. For more information about this command, check out its man page. I tested under Mac OS X and Xubuntu 9.04

lshw -C disk -html > /tmp/diskinfo.html
vmstat 1 10 | /usr/xpg4/bin/awk -f ph-vmstat.awk
2009-05-04 04:55:00
User: MarcoN
Functions: vmstat
5

% cat ph-vmstat.awk

# Return human readable numbers

function hrnum(a) {

b = a ;

if (a > 1000000) { b = sprintf("%2.2fM", a/1000000) ; }

else if (a > 1000) { b = sprintf("%2.2fK", a/1000) ; }

return(b) ;

}

# Return human readable storage

function hrstorage(a) {

b = a ;

if (a > 1024000) { b = sprintf("%2.2fG", a/1024/1024) ; }

else if (a > 1024) { b = sprintf("%2.2fM", a/1024) ; }

return(b) ;

}

OFS=" " ;

$1 !~ /[0-9].*/ {print}

$1 ~ /[0-9].*/ {

$4 = hrstorage($4) ;

$5 = hrstorage($5) ;

$9 = hrnum($9) ;

$10 = hrnum($10) ;

$17 = hrnum($17) ;

$18 = hrnum($18) ;

$19 = hrnum($19) ;

print ;

}

export LSCOLORS=gxfxcxdxbxegedabagacad
2009-05-04 04:07:36
User: haivu
Functions: export
Tags: bash ls osx
2

I use terminal with black background on the Mac. Unfortunately, the default ls color for the directory is blue, which is very hard to see. By including the line above in my ~/.bash_profile file, I changed the directory's color to cyan, which is easer to see. For more information on the syntax of the LSCOLORS shell variable:

man ls

I tested this command on Mac OS X Leopard

read -p "Which station? "; mplayer --reallyquiet -vo none -ao sdl http://somafm.com/startstream=${REPLY}.pls
2009-05-04 00:26:19
User: denzuko
Functions: read
11

This command asks for the station name and then connects to somafm, Great for those who have linux home entertainment boxes and ssh enabled on them, just for the CLI fiends out there ( I know I'm one of them ;)

Also, don't forget to add this as alias(ie alias somafm="read -p 'Which Station? "; mplayer --reallyquite -vo none -ao sdl

pi 66 | number
2009-05-03 22:10:58
0
pi 66

This prints out the first 66 digits of pi.

number

This takes any number (no more than 66 digits long) from stdin (or on the command line), and tells you how to say it. E.g

number 365

outputs "three hundred sixty-five"

command | figlet
2009-05-03 21:20:46
User: isaacs
Functions: command
Tags: figlet awesome
22

Pipe any command through figlet to make the output more awesome. Example:

ls | figlet
gnuplot -persist <(echo "plot '<(sort -n listOfNumbers.txt)' with lines")
2009-05-02 13:46:02
User: penthief
Functions: echo
21

Useful when you've produced a large file of numbers, and want to quickly see the distribution. The value of y halfway along the x axis is the median. Simple!

Just create the listOfNumbers.txt file with a number on each line to try it out.

sed G
2009-05-02 12:11:40
Functions: sed
-1

G option cause a file to be spacing line by line.

mencoder -oac copy -ovc copy part1.avi part2.avi part3.avi -o full_movie.avi
2009-05-02 07:44:32
User: pyrho
4

Using mplayer's mencoder, you can merge video files together.

'-oac' specifies the audio encoding (here copy, to just copy and not compress)

'-ovc' specifies the video encoding (same thing).

symlinks -r $(pwd)
2009-05-01 23:33:10
User: kFiddle
Tags: symlinks links
6

The symlinks command can show status of all symbolic links, including which links are dangling, which symlinks point to files on other file systems, which symlinks use ../ more than necessary, which symlinks are messy (e.g. having too many slashes or dots), etc. Other useful things it can do include removing all dangling links (-d) and converting absolute links to relative links (-c). The path given must be an absolute path (which is why I used $(pwd) in the example command).

gdb command: apropos <keyword>
2009-05-01 23:19:35
User: kFiddle
Functions: apropos gdb
Tags: gdb apropos help
0

Most of you are probably familiar with the "apropos" command for searching man pages. However, did you know there's a similar command inside of gdb? If, for example, you wanted to know all gdb commands that related to threads, you could type "apropos thread". Type "help some_command" to receive more information about a command. Type "help" by itself to see a list of help topics.

tar cvzf - data1 data2 | uuencode data.tar.gz | mail -s 'data' you@host.fr
2009-05-01 23:13:08
User: log0
Functions: mail tar uuencode
1

An easy one but nice to keep in mind.

wodim cdimage.iso
2009-05-01 21:53:27
8

Does life get much easier? Read up about wodim for an understanding of its origins in relation to the older `cdrecord` utility