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,927 results
sudo ifconfig wlan0 | grep inet | awk 'NR==1 {print $2}' | cut -c 6-
2013-02-18 14:10:07
User: mouths
Functions: awk cut grep ifconfig sudo
-1

On wired connections set 'eth0' instead of 'wlan0'

sqlite3 $HOME/.dropbox/config.db "select value from config where key like '%dropbox_path%'"
2011-06-05 08:26:02
User: mobilediesel
-1

Newer versions of Dropbox let you choose the location for your Dropbox folder. If you use script to put things into your Dropbox folder (todo list, screenshots, torrents etc.) but have the Dropbox folder in different locations on your other computers this lets you use the same script on all systems without having to tell it where the Dropbox folder is.

script -qf | tee >(nc -l -p 5000)
ct find -avobs -nxname -element 'brtype(branch_name)' -print 2>/dev/null
for f in *.ogg ; do mplayer -quiet -vo null -vc dummy -ao pcm:waveheader:file="$f.wav" "$f" ; done
CLASSPATH=.; export CLASSPATH=$CLASSPATH$(find "$PWD" -name '*.jar' -type f -printf ':%p\n' | sort -u | tr -d '\n'); echo $CLASSPATH
openssl req -new -x509 -extensions v3_ca -days 1100 -subj "/C=CA/ST=CA/L=SomeCity/O=EXAMPLE Inc./OU=Web Services/CN=example.com/emailAddress=postmaster@example.com" -nodes -keyout web.key -out web.crt
tar cf - . | (cd /new/dir; tar xvf -)
2009-03-09 20:30:34
User: jauderho
Functions: cd tar
-1

Add z to the flags to enable compression.

head -n X | tail -n 1
2010-07-08 22:06:39
User: infinull
Functions: head tail
-1

using tail first won't do it because tail counts from the bottom of the file. You could do it this way but I don't suggest it

export PATH=$PATH$(find "$PWD" -name '.*' -prune -o -type f -a -perm /u+x -printf ':%h\n' | sort -u | tr -d '\n'); echo $PATH
2011-03-11 19:31:17
User: dexterhu
Functions: echo export find sort tr
-1

(1) don't run twice, or the same folder will occur in $PATH.

(2) otherwise you need to start a new terminal

dpkg -l | sed '/^rc/!d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/' | xargs -r sudo apt-get -y purge
nl <filename>
2010-01-06 16:14:43
User: SuperFly
Functions: nl
-1

Works in RHEL5 and derivatives.

route -n | grep "^0\." | awk '{print "Gateway to the World: "$2", via "$NF""}'
add "ssh $1@$2" in /usr/sbin/connect with executable permission, now use commad "connect user 192.168.1.1"
2012-01-27 12:50:20
-1

I will ssh to ip address 192.168.2.1 with user name user.

"connect user 192.168.1.1" is same as "ssh user@192.168.1.1"

tail -f logfile | logtop
2012-06-24 19:18:30
User: Sizeof
Functions: tail
Tags: tail
-1

logtop show number of lines per second, also classify them so you can show a "top" of every aspect of your logfile :

tail -f access.log | awk '{print $1; fflush();}' | logtop

lsof -p <process_id> | wc -l
while true; do while [ `date +%H%M` == "1857" ] ; do sleep 1s; yes | head -n 2000 > /dev/dsp; done; done;
2011-04-23 14:44:26
User: mrwill
Functions: head sleep yes
-1

this command will beep like an alarm for one minute from 18:57. you can change "1857" to your desired time.

you should have alsa-oss package installed, and you should also be root or part of "audio" group.

ps aux | awk {'sum+=$3;print sum'} | tail -n 1
xxdiff -r --exclude=.svn
2009-02-09 23:07:07
User: andrewf
-1

Needs xxdiff installed, which looks a bit clunky but is an extremely powerful graphical diff.

explorer /e,.
2009-02-13 16:00:19
User: piyo
-1

Sometimes I want to use the mouse to move/copy/delete files.

(I also sometimes feel like a nut, sometimes I don't.)

This is for Windows 2000 and later, probably.

Tested on Windows XP, cmd.exe.

http://support.microsoft.com/kb/130510

CONVERT D: /FS:NTFS
2009-02-18 05:56:07
User: starchox
-1

You can convert a FAT or FAT32 volume to an NTFS volume without formatting the drive, though it is still a good idea to back up your data before you convert.

netstat -rn | awk '/UG/{print $2}'
2010-08-09 15:56:02
User: putnamhill
Functions: awk netstat
-1

Tested on CentOS, Ubuntu, and MacOS.

cat -n FILE | grep -C3 "^[[:blank:]]\{1,5\}NUMBER[[:blank:]]"
2009-05-17 18:19:55
User: lv4tech
Functions: cat grep
-1

This is useful for displaying a portion of a FILE that contains an error at line NUMBER

awk '/Table structure for table .table01./,/Table structure for table .table02./{print}' <file> > restored_table.sql
2010-08-09 18:23:13
User: din7
Functions: awk
-1

This will look through file and print the data in between the pattern matches. It's great for restoring tables from a mysqldump backup. You can then import it back into your database with:

mysql -u <user> -h <host> <database> < restored_table.sql
(sleep 3; echo "MyAwesomePassword"; sleep 3) |socat - EXEC:'ssh username@server "hostname"',pty,setsid,ctty
2011-08-24 14:13:18
User: TommyBotten
Functions: echo sleep
Tags: socat pts
-1

You should really use keys. Really. I'm serious.

But if you have to add your key, change password etc. for a long list of servers, this might help.