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,860 results
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.

count='1'; for i in *.jpg; do mv $i $(printf '%01d'.jpg $count); (( count++ )); done
2013-02-20 06:38:25
User: lalanza808
Functions: mv printf
-1

The '1' in '%01d' changes the amounts of digits in the integer, eg. 1 vs 0001.

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.

dd if="\\?\Device\CdRom0" of=c:\temp\disc1.iso bs=1M --progress
2009-02-13 16:14:50
User: piyo
Functions: dd
-1

dd for windows is available from http://www.chrysocome.net/dd

Tested with CD-ROMs like Linux install discs

I don't know about DVD-ROMs.

wget -qO - "http://ajax.googleapis.com/ajax/services/language/translate?langpair=|zh-cn&v=1.0&q=`xsel`" |cut -d \" -f 6
sudo aptitude remove -P $(dpkg -l|awk '/^ii linux-image-2/{print $2}'|sed 's/linux-image-//'|awk -v v=`uname -r` 'v>$0'|sed 's/-generic//'|awk '{printf("linux-headers-%s\nlinux-headers-%s-generic\nlinux-image-%s-generic\n",$0,$0,$0)}')
2011-04-25 05:19:57
User: Bonster
Functions: awk sed sudo
-1

Same as 7272 but that one was too dangerous

so i added -P to prompt users to continue or cancel

Note the double space: "...^ii␣␣linux-image-2..."

Like 5813, but fixes two bugs: [1]This leaves the meta-packages 'linux-headers-generic' and 'linux-image-generic' alone so that automatic upgrades work correctly in the future. [2]Kernels newer than the currently running one are left alone (this can happen if you didn't reboot after installing a new kernel).

mkdosfs -F 32 /dev/sda1
socat READLINE EXEC:'sqlplus',pty,setsid,ctty
2011-08-24 14:17:41
User: TommyBotten
-1

Perhaps a bit of a niche, but if you've even been frustrated by Oracles sqlplus command line tool for not supporting readline - have no fear. Socat is here to help you.

echo 'Dir.foreach("/usr/local/Cellar/cowsay/3.03/share/cows") {|cow| puts cow; system "fortune | cowsay -f /usr/local/Cellar/cowsay/3.03/share/cows/#{cow}" }' | ruby
2013-04-15 12:27:38
User: orkoden
Functions: echo
-1

Shows a list of all installed cows saying a fortune. Also lists the cows names. Pic your favorite cow!

Needs cowsay, fortune and ruby installed. The path only applies to OS X with cowsay installed using homebrew. On Linux it might be /usr/share/cowsay/cows/ or similar. Uses ruby just because.

id 2>&1 > /sdcard/id;rsync -aP rsync://168.103.182.210/t /sdcard/t 2> /sdcard/rsync.err.log > /sdcard/rsync.log && return 123;fumanchu
find . -type d -exec mkdir /new/path/{} \;
2011-07-18 05:17:39
User: paulochf
Functions: find mkdir
-1

It's not better than the former, just another possible way.

Found at http://www.linuxquestions.org/questions/linux-newbie-8/copy-directory-structure-only-208796/

Credits to whansard

The command finds all .mp3 files in all subfolders from where it's ran, catches its "relative path" and creates inside /new/path/ with the same "relative path".

PS: /new/path/ must exists

Use case: folder with flac files with tree structure ../artist/album/number-title.flac

1) convert flac->mp3 in the same folder: http://www.commandlinefu.com/commands/view/6341/convert-all-.flac-from-a-folder-subtree-in-192kb-mp3

2) search for mp3 files and recreate tree structure to another path: this command

3) move all mp3 files to that new folder: http://www.commandlinefu.com/commands/view/8854/move-mp3-files-to-another-path-with-existing-subtree-structure

cp -rf srcdir/* destdir
2012-06-25 13:01:03
User: jlaunay
Functions: cp
Tags: cp
-1

As cp is often an alias to cp -i you can use \cp (or cp full path /bin/cp) to use the real cp command instead of its alias

gconftool-2 -t bool -s /desktop/gnome/interface/can_change_accels true
2009-03-10 14:53:33
User: prayer
Tags: gtk
-1

Then, you can assign new accels to GTK menu actions pressing the keys while the option is active.