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,847 results
netstat -an | grep -i listen
alias wordpress='mkdir wordpress && cd wordpress && wget http://wordpress.org/latest.tar.gz && tar -xvzf latest.tar.gz && mv wordpress/* . && rm -rf latest.tar.gz wordpress && cp wp-config-sample.php wp-config.php'
ifconfig | grep "inet [[:alpha:]]\+" | cut -d: -f2 | cut -d' ' -f2
2009-07-24 13:16:37
User: feraf
Functions: cut grep ifconfig
Tags: Linux ifconfig
-6

Get the IP address of all your network cards.

echo > filename
sudo wget -c "http://nmap.org/dist/nmap-5.00.tar.bz2" && bzip2 -cd nmap-5.00.tar.bz2 | tar xvf - && cd nmap-5.00 && ./configure && make && sudo make install
2009-07-26 11:36:53
User: hemanth
Functions: bzip2 cd make sudo tar wget
-6

Just copy and paste the code in your terminal.

Note : sudo apt-get for debian versions , change as per your requirement .

Source : www.h3manth.com

find ~ -name "*.pyc" -exec rm {} \;
source ~/.bash_profile
2009-06-29 19:26:43
-6

when editing .bash_profile (or .bashrc), run this to use the new version without having to exit and open a new terminal

grep -vf file1 file2
2010-06-15 19:43:08
User: decept
Functions: grep
-6

-f file

-v invert-match : invert the sense of matching, to select non matching lines

ssh -X -l user 192.168.1.25
2013-04-30 13:48:28
User: xmuda
Functions: ssh
-6

One time you logged in, you can prove these method just writing "firefox".

for i in $(find . -name *replaceme*);do mv "$i" "${i//replaceme/withme}"; done
2010-08-19 03:22:15
User: lefnire
Functions: find mv
Tags: bash
-6

rename is a great command, but can't get it to work on mac.

find . -maxdepth 1 -type d -not -name . -exec du -sh {} +
2009-12-11 14:37:26
User: sorpigal
Functions: du find
-6

Parsing the output of ls is never a good idea for any reason. Using find this way:

- works with files that have spaces in their names.

- actually lists "sub folders" and not of all files and folders.

- does not break if there are a huge number of files in the current directory.

vi ~/.crontab && crontab ~/.crontab
2009-08-16 08:09:15
User: micha
Functions: crontab vi
-6

this lets you edit a crontab file (which may be used as a backup as well) and insert this into your crontab. this way is especially handy, when multiple users are working on one account (e.g. root)

rm -rf `find . -type f -name *.htm`
curl icanhazip.com
:w!
mount -t vfat /dev/sdx1 /media/psp/
test `uname` = Linux && lsb_release -a || ( test `uname` = SunOS && cat /etc/release || uname -rms )
2009-07-07 20:51:30
User: virtualshock
Functions: cat test uname
-7

Found in comments section works on most Linux flavors.

echo 0 >/selinux/enforce
2010-02-17 16:33:26
User: svnlabs
Functions: echo
-7

just change SELINUX=enforcing to SELINUX=permissive, and you're done. Reboot if you want to prove it.

savesIFS=$IFS;IFS=$(echo -en "\n\b"); for items in `ls *.7z`; do 7zr e $items ; done; IFS=$saveIFS
uname -a
last reboot
ps aux | grep -i firefox | grep -v grep | awk '{print $2}' | xargs -t -i kill -9 {}
2009-02-19 18:50:00
User: blackdude
Functions: awk grep kill ps xargs
-7

This is a nice way to kill processes.. the example here is for firefox!!! substitute firefox for whatever the process name is...

curl -s -u user:password http://twitter.com/statuses/friends_timeline.rss | grep title | sed -ne 's/<\/*title>//gp' | head -n 4 | say -v Bruce
2009-03-20 20:14:13
User: sixtus
Functions: grep head sed
-7

You need curl.. and a Mac of course.

zcat /usr/share/man/man1/grep.1.gz | grep "color"
2009-02-04 09:38:45
User: root
Functions: grep zcat
-7

This decompresses the file and sends the output to STDOUT so it can be grepped. A good one to put in loops for searching directories of gzipped files, such as man pages.