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,925 results
watch ifconfig eth0
sudo find / -user root -perm -4000 -print
^D
2009-02-17 18:10:31
User: tlknv
1

Use ^D instead of exit.

Also ^D ends input stream when you use terminal for typing into standard input.

mysqldump --add-drop-table --extended-insert --force --log-error=error.log -uUSER -pPASS OLD_DB_NAME | ssh -C user@newhost "mysql -uUSER -pPASS NEW_DB_NAME"
2009-02-17 17:57:53
User: Tscherno
Functions: ssh
27

Dumps a MySQL database over a compressed SSH tunnel and uses it as input to mysql - i think that is the fastest and best way to migrate a DB to a new server!

vncserver -nohttpd -name hidef-server -depth 24 -geometry 1440x900
2009-02-17 17:50:33
User: starchox
Tags: Network , net
3

-nohttpd don't run mini-httpd if VNC java applet is found

-name change the name of the desktop, it's passed to xstartup script via $VNCDESKTOP, run different set of apps acording the name.

-depth pixel depth in bits of the desktop, default is 16

-geometry size of the desktop, default is 1024x768

cd `pwd -P`
2009-02-17 17:21:24
User: Davvolun
Functions: cd
16

If you use symlinks a lot, especially nested symlinks, this puts you back on the absolute path to command-line-fu-nirvana. (Note the backticks around pwd).

history -w <switch to another terminal> history -r
2009-02-17 17:11:31
User: tlknv
7

Or just do history -w before opening another terminal.

ls -1 . dir2 dir3|sort|uniq -d
2009-02-17 16:29:03
User: tlknv
Functions: ls
1

cat file1 file2 file3|sort|uniq -d

finds the same lines in several files, especially in files with lists of files.

ssh -CNL 3306:localhost:3306 user@site.com
ssh -D 8888 user@site.com
2009-02-17 15:34:27
User: wesrog
Functions: ssh
5

Simply change your web browser's proxy settings to point to a SOCKS proxy at port 8888 and you're good to go.

kill -9 $$
2009-02-17 15:10:29
User: chanux
Functions: kill
-2

Kill -9 immediately kills the given process number. $$ is the process ID of the process you are in.

find apps/ -name "*.svn-base" -prune -o -print -name "*.php" | xargs grep -E 'new .+Form\('
2009-02-17 14:56:01
User: ubermuda
Functions: find grep xargs
-1

finds all forms instanciated into a symfony project, pruning svn files.

mkdir -p work/{d1,d2}/{src,bin,bak}
perl -pe 's/\d+/++$n/e' file.txt
cat /proc/cpuinfo
2009-02-17 14:50:29
User: stinger
Functions: cat
-4

how to get full cpu info of your (linux) box

ls -1 /bin | xargs -l1 whatis 2>/dev/null | grep -v "nothing appropriate"
2009-02-17 14:46:01
User: stinger
Functions: grep ls whatis xargs
4

Get simple description on each file from /bin dir, in list form, usefull for newbies.

for FILE in $(ls); do [COMMAND]; done
2009-02-17 14:42:46
User: stinger
-4

# Small for loop, that can list files in dir, and after that executes

# [COMMAND] of your choice, usefull for example rename, move, tar etc..

# change cmd's for different results :)

echo $RANDOM
nc -v -l 80 < file.ext
2009-02-17 14:39:52
User: moz667
79

From the other machine open a web navigator and go to ip from the machine who launch netcat, http://ip-address/

If you have some web server listening at 80 port then you would need stop them or select another port before launch net cat ;-)

* You need netcat tool installed

history | awk '{print $2}' | sort | uniq -c | sort -rn | head
grep -c -e '^cpu[0-9]\+' /proc/stat
egrep -o '\b[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\b' access.log | sort -u
^J tput sgr0 ^J
2009-02-17 09:57:22
User: berta
Functions: tput
1

when your terminal session seems unrensponsive (this normally happen after outputting some binary data directly on your standard output) it may me saned by hitting:

CTRL+J tput sgr0 CTRL+J

Note: don't press the Enter key, just ctrl+j

curl http://root:PASSWORD@ROUTER_DYN_DNS/bwm/tomato_rstatsa001839ceb1d4.gz?_http_id=HTTPID > $HOME/Dropbox/Backups/tomato_stats.gz
2009-02-17 09:45:34
User: moritz
0

You must get your Backup Url from: http://ROUTER_DYN_DNS/admin-bwm.asp under "Backup".

I set it up in a curl

find . -type f|while read f; do mv $f `echo $f |tr '[:upper:]' '[ :lower:]'`; done
2009-02-17 09:44:38
User: berta
Functions: find mv read
9

or, to process a single directory:

for f in *; do mv $f `echo $f |tr '[:upper:]' '[:lower:]'`; done