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,488 results
zip -r -9 /var/www/html/project.zip /var/www/html/project
date | md5sum
find . -type d -name 'CVS' | xargs rm -r
ls -1 static/images/ | while read line; do echo -n $line' '[; grep -rc $line *|grep -v ".svn"|cut -d":" -f2|grep -vc 0| tr "\n" -d; echo -n ]; echo ; done
2009-03-20 20:33:36
User: psytek
Functions: cut echo grep ls read tr
-5

This command will grep the entire directory looking for any files containing the list of files. This is useful for cleaning out your project of old static files that are no longer in use. Also ignores .svn directories for accurate counts. Replace 'static/images/' with the directory containing the files you want to search for.

while true; do ifconfig eth0 | grep "inet addr:"; sleep 60; done;
2009-04-01 19:29:28
User: bandit36
Functions: grep ifconfig sleep
Tags: script while loop
-5

You can use this to loop any command to periodically see the output.

while true; do [YOUR COMMAND HERE]; sleep [# of seconds]; done;

Alternatively, you can put it in a simple shell script to save typing!

#/!bin/bash

while true; do $1; sleep $2; done;

/path/to/script.sh "ifconfig eth0 | grep 'inet addr:'" 60
scp /home/svnlabs.txt root@92.178.0.56:/home/
set colsep "{char}"
2011-04-05 10:48:48
User: EBAH
Functions: set
Tags: oracle
-5

set colsep "&TAB" -- for tab separator

set colsep "|" -- for pipe separator

etc...

du -sh some/directory
2010-02-21 02:08:28
User: Jacolyte
Functions: du
-5

Displays only the subtotal size of a directory with the -s option, and in human readable format.

ssh -X johndoe@123.456.789
2011-05-19 21:28:25
User: evandrix
Functions: ssh
-5

To start X11 display only on your local machine: xeyes &

Extensions to basic command: ssh -X -f user@remotehost xcalc -bg black -fg green

xdg-open http://xkcd.com/
2010-08-25 19:14:11
-5

KISS

To get a random xkcd comic:

xdg-open http://dynamic.xkcd.com/random/comic/
psg() { ps aux | grep "[${1[1]}]${1[2,-1]}"; }
2009-09-07 04:37:11
User: jedahan
Functions: grep ps
-5

alias ps?='psg' for maximum hawtness. Works in bash or zsh.

for %f in (c) do dir %f:\*.jpg /s /p
2009-05-05 18:28:18
User: copremesis
Functions: dir
-5

there is no explicit find command in DOS you can create a batch file with this one and find all jpegs on the C drive ...

note: if creating a batch file "find.bat" the syntax changes to:

for %%f in (c) do dir %%f:\%1 /s /p

you can then use

find *.jpg
for f in *; do mv $f <target_path>; done;
2009-07-09 12:07:49
User: fritz_monroe
Functions: mv
-5

In my job I often have to deal with moving 100,000 files or more. A mv won't do it because there are too many. This will move everything in the current directory to the target path.

ifconfig | grep addr:192 | sed s/Bcast.*// | sed 's/^.*inet addr://'
2010-03-26 07:37:21
User: hasenj
Functions: grep ifconfig sed
-5

This assumes your local ip starts with 192.something (e.g. 192.168), it greps ifconfig output for an ip that starts with 192, then strips the extra garbage (besides the ip)

Maybe `ifconfig | grep addr | grep Bcast` would also do it

for x in *.ogg; do ffmpeg -i "$x" "`basename "$x" .ogg`.mp3"
declare -i i; i=0; for file in *; do i=`expr $i+1`; mv "$file" $i; done;
2010-08-26 12:24:38
User: themiurgo
Functions: file mv
-5

Renames files in a directory to incremental numbers, following alphabetic order. The command does not maintain extensions.

rm -rf `find ./ -iname *.svn*`
declare -i i=0 ; for file in * ; do i=$[$i+1] ; mv "$file" $i; done
say sofa king great
2010-07-30 17:11:45
User: scotbuff
-5

Just type it and hit enter and you will get it.

find directory/ |xargs grep -i "phrase"
ps aux | grep 'httpd ' | awk {'print $2'} | xargs kill -9
cat /etc/debian_version
2009-08-05 14:47:05
User: caiosba
Functions: cat
-5

Easy way to find out what Debian version your machine is running

sudo alien --to-deb Your_PackAge.rpm
2009-09-27 13:49:07
User: eastwind
Functions: sudo
-5

convert to debian package file (deb) a redhat package file (rpm) , then you can install it by using dpkg , require alien package ( sudo apt-get install alien first )

for file in `find . -iname "FILENAME"`; do cat $file | sed "s/SEARCH_STRING/REPLACE_STRING/" > $file.tmp; mv $file.tmp $file; done
logs=$(find . -name *.log);for log in $logs; do cat /dev/null > $log;done
2009-03-04 10:05:48
Functions: cat find
-5

This find files of name like *.log and truncates them.