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
echo "sed -e"|perl -pe 's/sed -e/perl -pe/'
2009-02-16 18:39:06
User: drossman
Functions: echo
-1

Replace sed regular expressions with perl patterns on the command line.

The sed equivalent is: echo "sed -e"|sed -e 's/sed -e/perl -pe/'

dd if=/dev/zero of=/swapfile bs=1M count=64; chmod 600 /swapfile; mkswap /swapfile; swapon /swapfile
2009-02-16 18:36:38
User: starchox
Functions: chmod dd mkswap swapon
8

In addition to a swap partition, Linux can also use a swap file. Some programs, like g++, can use huge amounts of virtual memory, requiring the temporary creation of extra space.

find . -type f -perm +0111 -print
scp user@hostb:file user@hostc:
2009-02-16 18:33:08
User: drossman
Functions: scp
8

While at the command line of of hosta, scp a file from remote hostb to remote hostc. This saves the step of logging into hostb and then issuing the scp command to hostc.

function man2pdf(){ man -t ${1:?Specify man as arg} | open -f -a preview; }
2009-02-16 18:29:35
User: piXelz
Functions: as man
4

Simply pass an argument to the script to convert the manual page to a PDF:

man2pdf drutil
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain system -domain user
apache2 -t -D DUMP_MODULES
2009-02-16 17:30:20
User: ElAlecs
Tags: apache httpd
5

This let you know which modules has loaded the Apache server, very useful to know if the mod_rewrite is ready to use.

_cd ~/nsfw; mplayer midget_donkey.mpeg
2009-02-16 17:19:40
User: Kirbe
5

Note the extra space before the command (I had to put it as an underscore since the website eats up preceding spaces). That's all it takes. Now if you check your history with "$ history", it wont show up.

find . -name "*.jar" | xargs -tn1 jar tvf | grep --color "SearchTerm"
2009-02-16 17:18:36
Functions: find grep xargs
2

Great for finding which jar some pesky class is hiding in!

find . -name "*.pyc" -exec rm {} \;
2009-02-16 17:15:58
User: nsmgr8
Functions: find rm
-2

For a python project, sometimes I need to clean all the compiled python files. I have an alias 'rmpyc' to this command. This really saves me a lot of typing and hunting throughout the folders to delete those files.

for I in `find . -name "*.php"`; do sed -i "s/old name/new name/g" $I; done
2009-02-16 17:09:09
User: ruedu
Functions: sed
-1

So you have a web site and you've plastered your significant other's name all over it. But you broke up with them and have some new love in your life. How do you find all those instances of their name and replace them?

pushd /tmp
2009-02-16 16:52:59
User: ruedu
83

If are a Bash user and you are in a directory and need to go else where for a while but don't want to lose where you were, use pushd instead of cd.

cd /home/complicated/path/.I/dont/want/to/forget

pushd /tmp

cd thing/in/tmp

popd (returns you to /home/complicated/path/.I/dont/want/to/forget)

for I in `echo "show databases;" | mysql | grep -v Database`; do mysqldump $I > "$I.sql"; done
2009-02-16 16:41:05
User: ruedu
Functions: grep
9

Backups all MySQL databases to individual files. Can be put into a script that grabs current date so you have per day backups.

ip route | grep default | awk '{print $3}'
2009-02-16 16:29:03
User: ruedu
Functions: awk grep route
1

This gets you your default route programatically, useful for scripts

mysqldump --add-drop-table -uroot -p "DB_name" | replace CHARSET=latin1 CHARSET=utf8 | iconv -f latin1 -t utf8 | mysql -uroot -p "DB_name"
rsync --partial --progress --rsh=ssh SOURCE DESTINATION
2009-02-16 16:22:10
User: episodeiv
Functions: rsync
14

Put it into your sh startup script (I use

alias scpresume='rsync --partial --progress --rsh=ssh'

in bash). When a file transfer via scp has aborted, just use scpresume instead of scp and rsync will copy only the parts of the file that haven't yet been transmitted.

getent [group|hosts|networks|passwd|protocols|services] [keyword]
2009-02-16 15:57:26
User: raphink
Functions: getent
8

getent allows to get the contents of several databases in their native file format even if they are not actually in /etc. For example, if you are using a LDAP or a DB to authenticate your users, you won't find their info by catting /etc/passwd, but "getent passwd" will concatenate /etc/passwd to the LDAP/DB.

vimtutor
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n | tail
2009-02-16 15:48:27
User: TuxOtaku
Functions: awk cut netstat sort uniq
2

This command does a tally of concurrent active connections from single IPs and prints out those IPs that have the most active concurrent connections. VERY useful in determining the source of a DoS or DDoS attack.

du --max-depth=1 -m
cal [[month] year]
ruby -ropen-uri -e 'require "hpricot";(Hpricot(open("http://commandlinefu.com"))/".command").each{|c| puts c.to_plain_text}'
2009-02-16 15:32:58
2

Uses the fabulous Hpricot library to parse HTML from Ruby. Extracts all elements of "command' class and displays unescaped text from inside these elements. The following command can help install dependencies (apart from Ruby itself)

gem sources -a http://gems.github.com && sudo gem install why-hpricot
man -k <keyword>
2009-02-16 15:28:57
User: raphink
Functions: man
3

Search manpages for a keyword. Very useful when you don't know where to find the information.

kdialog --passivepopup <text> <timeout>
2009-02-16 15:09:27
User: raphink
Tags: KDE
6

Display a passive popup during seconds. Additionnaly, --title can be used to set the title of the popup. This is a nice way to communicate with a desktop user of a machine you have an SSH access on :

DISPLAY=:0 sudo -u $user -H kdialog --passivepopup "Hello you" 10 --title "cli IM"