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,610 results
for i in $(grep 'mystring' myfile1)|awk '{print $1}'); do grep $1 myfile2;done
for i in $(seq 0 5) ; do echo "5 - $i" | bc -l ; sleep 60 ; done && echo "bye, bye" && shutdown -h now
2009-03-13 12:16:35
User: arctarus
Functions: bc echo seq shutdown sleep
-14

command to turn off your computer when you go home and can not wait

ls | grep *.txt | while read file; do cat $file >> ./output.txt; done;
yum install vixie-cron crontabs
fbemailscraper YourFBEmail Password
for dir in $(ls); do du -sk ${dir}; done
2009-03-24 13:42:55
User: morlockhq_
Functions: dir du
-15

Sometimes you want to know the summary of the sizes of directories without seeing the details in their subdirectories. Especially if it is going to just scroll off the screen. This one liner summarizes the disk usage of any number of directories in a directory without giving all the details of whats happening underneath.

:!start c:\progra~1\Opera\opera.exe http://www.commandlinefu.com
perl -e 'print "\x41\x72\x74\x20\x6f\x66\x20\x68\x61\x63\x6b\x69\x6e\x67\x2e\x2e\x2e\n" x 100'
/bin/bash echo -n "Let's POST MORE, PLEASE!"
2010-02-05 18:52:45
User: editorreilly
Functions: echo
-15

I absolutely love this website, and appreciate every contribution. This is the first place I go when I'm stuck, you all have some great ideas. But contributions seem to be slipping a little. If all of us could contribute more code from time to time, this site would be absolutely incredible. Since I'm a relative newcomer to commandline-fu, I don't have the knowledge to contribute much, but I will do what I can.

nohup nautilus &
. ./cd_some_dir.sh
2009-02-19 19:02:21
User: jcgam69
-16

The script contains a single command:

cd /a/long/directory/path/i/can/never/remember

scp ~/.ssh/id_rsa.pub user@remote:.ssh/authorized_keys
2010-08-25 23:24:09
User: CharlieInCO
Functions: scp
-16

Simply copies your public key to the remote system. For the first time, this will require a password for the user@remote account. From then on, ssh will ask for your private key keyphrase occasionally but you won't need to use the password. Very handy when you're moving files for testing etc.

dmesg | grep cpu
2009-04-03 01:57:04
User: kingji
Functions: dmesg grep
Tags: cpus
-16

get cpu info from dmesg

netstat -antp | grep 22
apache2ctl graceful
alias up="cd .."; alias upp="cd ../.."; alias uppp="cd ../../.."; alias upppp="cd ../../../.."; alias uppppp="cd ../../../../.."
reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SNMP\Parameters\ValidCommunities
not necessarily better, but many...!
2009-08-12 11:03:26
Tags: bash awk
-17

( IFS=:; for i in $PATH; do echo $i; done; )

echo $PATH|sed -e 's/:/\n/g' # but the tr one is even better of course

echo $PATH|xargs -d: -i echo {} # but this comes up with an extra blank line; can't figure out why and don't have the time :(

echo $PATH|cut -d: --output-delimiter='

' -f1-99 # note -- you have to hit ENTER after the first QUOTE, then type the second one. Sneaky, huh?

echo $PATH | perl -l -0x3a -pe 1 # same darn extra new line; again no time to investigate

echo $PATH|perl -pe 's/:/\n/g' # too obvious; clearly I'm running out of ideas :-)

who am i
2009-02-20 16:26:11
User: ozymandias
Functions: who
-18

In my work environment, we log onto the servers as our user ('user', in the sample ouput), and 'sudo su - root' to other accounts. This trick allows us to return the account name we logged in as -- and not the account name we currently are ('root', in this example).

Using this trick, you can build other commands:

Set your CVSROOT env variable to your account name:

CVSROOT=$(who am i | awk '{print $1}')@cvs.server.example.com:/cvsroot

SCP a file to another server:

scp file.txt $(who am i | awk '{print $1}')@some.other.server.com:.

This works out great in my environment, as we can include this in our documentation and make the comands more easy to copy/paste for different users, and not have to set all sorts of variables, or modify the docs for each user.

whoami gives you the name of the user you currently are, not the user you logged on originally as.

who gives you a listing of every single person logged onto the server.

who am i gives you the name of the user you logged on as, and not who you changed to with su.

Look at the following scenario:

whoami

user

su -

# whoami

root

# who am i

user pts/51 2009-02-13 10:24 (:0.0)

whoami != who am i

while true; do eject /dev/cdrom && eject -t /dev/cdrom; done
2009-02-11 04:41:19
User: fmdlc
Functions: eject
-18

This open the cd rom device and close it in a loop

ls -l
ls ~
2010-09-12 10:45:01
User: harish
Functions: ls
-18

It will list all files in your home directory even if your current directory is not home directory

ls -l
alias vi='emacsclient -n'
2009-07-29 06:18:40
User: freestyler
Functions: alias
-18

add (server-start) in .emacs

ln