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,611 results
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

for ip in $(seq 1 25); do ping -c 1 192.168.0.$ip>/dev/null; [ $? -eq 0 ] && echo "192.168.0.$ip UP" || : ; done
2009-02-11 14:57:34
Functions: echo ping seq
0

this is very useful when there is a different network host to determine which are turned on or not

xrandr --output LVDS --auto --output VGA --auto --right-of LVDS
2009-02-11 13:20:17
User: root
7

You'll need to make sure your xorg.conf permits a virtual screen size this big. If it doesn't then xrandr should return a suitable error message that tells you the required size.

history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
rar a -m0 "${PWD##*/}.rar" *
2009-02-11 13:06:34
1

This command creates a rar archive from all files in the current folder and names the archive after the folder name.

dd if=/dev/zero bs=1M | ssh somesite dd of=/dev/null
du -sh
!!:gs/foo/bar
2009-02-11 10:20:15
User: Tronks
187

Very useful for rerunning a long command changing some arguments globally.

As opposed to ^foo^bar, which only replaces the first occurrence of foo, this one changes every occurrence.

diff <(head -500 product-feed.xml) <(head -500 product-feed.xml.old)
2009-02-11 09:24:38
User: root
Functions: diff head
3

Useful for massive files where doing a full diff would take too long. This just runs diff on the first 500 lines of each. The use of subshells to feed STDIN is quite a useful construct.

echo $0
2009-02-11 08:58:01
User: yogsototh
Functions: echo
7

Return the current shell. It is better than print $SHELL which can sometimes return a false value.

while read line; do echo -e "$line@mail.com"; done < list.txt