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,621 results
pwd
2009-02-13 00:31:49
User: rothgar
Functions: pwd
-10

Simply displays your current working directory. Helps when you are buried deep in /etc or some other obscure place.

rpm -e --allmatches filename.rpm
2009-02-12 23:09:24
User: sohaileo
Functions: rpm
1

If somehow if you get more than 1 same name rpm package install, then it cannot be removed by using simple rpm -e as it gives you more than one rpm matches error. The --matches will help to remove all the same name rpm packages.

/etc/security/bsmconv
2009-02-12 22:53:02
User: mshenoy
0

Once Enabled this command enables a trail of all processes on the system. As the name suggested auditing for Solaris machines.

BSM creates a number of files in the /etc/security directory.

tar -zcps <dir> -X <(find <dir> -type f -mtime -<days>) |ssh user@backuphost tar -xzpsC /data/bkup
2009-02-12 22:31:58
User: zb
Functions: find tar
-3

due to bug can not comment

find /tmp -type f -printf 'rm "%p";\n'
2009-02-12 20:23:24
User: zb
Functions: find
4

add |sh when you agree the list, I often use that method to prevent typos in dangerous or long operations

find ./backup -type f -print0 | xargs -0 md5sum > /checksums_backup.md5
tail -f /var/log/messages
2009-02-12 19:30:33
User: nicdev
Functions: tail
-2

Use this command to see logs update in real time

telnet <ip> <port>
2009-02-12 19:11:03
User: leprasmurf
Functions: telnet
-2

Telnet will make a tcp connection to a remote ip/port to test connectivity. If it times out, it's not reaching the host (maybe the firewall is blocking it). If connection is refused, it's reaching the host, but either the service is not listening on that port, or it's locked.

find * -type d -exec mkdir /where/you/wantem/\{\} \;
find . -name "*.php" -exec iconv -f ISO-8859-1 -t UTF-8 {} -o ../newdir_utf8/{} \;
lsof -u www-data
usermod -a -G groupname username
find <dir> -type f -mtime +<days> -exec scp -r {} user@backuphost:/data/bkup \;
2009-02-12 07:43:29
User: rbattu
Functions: find scp
-1

U have to make key exchange in order to avoid continuous password prompt.

ps gv [pid] | head -2
2009-02-12 05:04:55
User: ren
Functions: head ps
-1

sh as:

#! /bin/sh

while [ 1 -ne 6 ]; do

pid=`ps -ef | grep -v "grep" | grep "trans_gzdy" | cut -c10-17`

ps gv $pid | head -2

sleep 1

done

check changes of RSS.

alias mute="dcop kmix Mixer0 toggleMasterMute\(\) ; dcop kmix Mixer0 masterMute\(\) | sed -e 's/true/muted/' -e 's/false/unmuted/' "
2009-02-12 04:56:33
User: wwest4
Functions: alias
1

arguably better than using the driver interface. lots of potentially cool stuff to be done w/ the dcop client.

>realpath ./somefile.c | xclip -selection c
2009-02-11 21:39:22
User: yalestar
1

Handy for those times you need to paste a file path in an IDE or some other app.

sudo apt-get install xclip

Then, for convenience, alias xclip to 'xclip -selection c' so you can just do something like realpath . | xclip

if [ ! -z "${DISPLAY}" ]; then someXcmd ; fi
2009-02-11 21:03:56
User: kmac
3

If you want to display a dialog (using xdialog/kdialog/zenity) you

need to make sure that you have a valid X session. Checks for

the existence of the DISPLAY variable.

nmap -sP 192.168.1.100-254
2009-02-11 20:44:43
User: wwest4
15

nmap accepts a wide variety of addressing notation, multiple targets/ranges, etc.

\[command]
2009-02-11 19:34:21
User: wwest4
83

e.g. if rm is aliased for 'rm -i', you can escape the alias by prepending a backslash:

rm [file] # WILL prompt for confirmation per the alias

\rm [file] # will NOT prompt for confirmation per the default behavior of the command

rm -- --myfile
nmap -sT -p 80 -oG - 192.168.1.* | grep open
2009-02-11 17:47:27
User: bendavis78
Functions: grep
18

Change the -p argument for the port number. See "man nmap" for different ways to specify address ranges.

cat .ssh/id_rsa.pub | ssh hostname 'cat >> .ssh/authorized_keys'
2009-02-11 17:40:12
User: bendavis78
Functions: cat hostname ssh
14

Just run the command, type your password, and that's the last time you need to enter your password for that server.

This assumes that the server supports publickey authentication. Also, the permissions on your home dir are 755, and the permissions on your .ssh dir are 700 (local and remote).

alias dir="ls -al"
2009-02-11 16:51:01
User: katylava
Functions: alias
0

If you come from a DOS background and accidentally use DOS commands often, this and others like it can be helpful. Add to your .bash_profile, or wherever you keep such things.

svn st | grep /main/java | awk '{print $2}' | xargs echo | xargs svn ci -m "my comment here"
alt + .
2009-02-11 15:26:34
User: vbs100
7

Insert the last argument to the previous command