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,485 results
sudo ifconfig -a | grep eth | grep HW | cut -d' ' -f11
curl http://www.chisono.it/ip.asp
screen -r irc || screen -S irc irssi
2012-10-19 12:12:54
User: daneoshiga
Functions: screen
Tags: bash screen irssi
-2

Tries to reattach to screen, if it's not available, creates one.

created an alias "irc" for it, since sometimes i forget if there already is a screen session running with irssi, this way I avoid creating a new one by mistake.

nano `which script`
2009-02-05 16:57:41
User: fzero
-2

Substitute nano with your favorite editor, of course.

zpool create tank mirror c0t0d0 c0t1d0 mirror c0t2d0 c0t3d0
2009-05-16 10:44:56
User: mnikhil
Tags: zfs zpool
-2

command creates a pool with two mirrors, where each mirror contains two disks.

for i in *.xml; do sed -i 's/foo/bar/g' "$i"; done
for ((;;)) do pgrep wget ||shutdown -h now; sleep 5; done
ls > ls; paste ls ls > ren; nano ren; sed 's/^/mv /' ren|bash; rm ren ls
2011-02-08 17:07:13
User: romulusnr
Functions: ls paste rm sed
-2

Instead of tedious manual mv commands and tabbing, this routine creates a file listing all the filenames in the PWD twice, edit the second instance on each line to the new name, then save the file, the routine does the rest. Feel free to replace nano with your holy war editor of choice.

You will get a lot of "mv: 'x' and 'x' are the same file" warnings, these could be cleaned up but the routine works.

sort --random-sort file
2011-12-10 20:28:54
User: arld101
Functions: sort
Tags: sort random
-2

Seeing that _sort_ its been used, why not just _use_ it. ;)

less -p pattern file.txt
find . -name '*.jpg' -o -name '*.JPG' | xargs -I{} mogrify -resize 1024">" -quality 40 {}
2013-06-20 15:20:29
Functions: find xargs
-2

First use find to find all the images that end with jpg or JPG in the current dir and all its children.

Then pipe that to xargs. The -I{} makes it so spaces in filenames don't matter.

The 1024">" makes it so it takes any image greater in dimension than 1024 and resizes them to 1024 width, but keeping aspect ratio on height.

Then it sets the image quality to 40.

Piping it through xargs means you avoid the file count limit, and you could run this on your entire file system if you wanted.

zpool create tank /path/to/file/a /path/to/file/b
2009-05-16 10:46:17
User: mnikhil
Tags: zfs zpool
-2

This command creates an unmirrored pool using

files. While not recommended, a pool based on files can be

useful for experimental purposes.

find . -name ".svn" -type d -exec rm -rf {} \;
2012-08-16 13:04:47
User: gigo6000
Functions: find rm
Tags: svn git rm
-2

This is useful when you are uploading svn project files to a new git repo.

ompload() { wget -O- - "$1" --quiet|curl -# -F file1=@- http://ompldr.org/upload|awk '/Info:|File:|Thumbnail:|BBCode:/{gsub(/<[^<]*?\/?>/,"");$1=$1;print}';}
2012-10-19 22:54:55
User: dzup
Functions: awk wget
-2

Like i said, i havent test it yet, all becouse my internet its soo slow, if you try and works please share, also be nice to do it using the direct url link.

netsh interface ip dump > current-interfaces.txt
2009-02-13 15:13:05
User: piyo
Functions: dump
-2

On Windows 2000 or newer, you can use the command line to save the current network interface info.

You can then edit the text file and re-apply it using the netsh -f command (or netsh exec). Keep a bunch of text files around to quickly switch connection info without using extra software.

http://en.wikipedia.org/wiki/Netsh

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

http://thelazyadmin.com/blogs/thelazyadmin/archive/2005/04/04/Using-Netsh-to-Manage-Network-Interfaces-Part-2.aspx

rm -f `find ./ | grep "\.\_.*"`
2010-11-16 20:52:33
User: edfuh
Functions: grep rm
-2

Mac OSX creates resource forks (http://en.wikipedia.org/wiki/Resource_fork) for every file, which are extremely annoying when transferring projects over to an Ubuntu server for instance

perl -e 'print "\n"x100'
2010-09-07 10:11:10
User: SunX
Functions: perl
-2

Perl variant of echo several blank lines command

echo '<?php echo str_rot13 ("Hello World") ?>' > hw.php && php hw.php && rm hw.php
2011-01-04 21:15:19
User: IsraelTorres
Functions: echo rm
-2

created and tested on:

ProductName: Mac OS X

ProductVersion: 10.6.5

BuildVersion: 10H574

arecord|aplay
ps aux| grep -v grep| grep httpd| awk {'print $2'}| xargs kill -9
export DISPLAY=$(tr '\000' '\n' < /proc/`pidof Xorg`/cmdline | egrep '^:[0-9]+')
2012-12-18 07:26:16
User: oernii2
Functions: egrep export tr
-2

Not always does Xorg run on :0. For times like those, this script allows you to find out which it is.

perl -e '$x = []; push @$x, eval { $x = 1; return $x = 1; }'
2009-10-07 22:42:18
User: dstahlke
Functions: eval perl return
-2

It is not easy to make perl give a segfault, but this does it. This is a known issue but apparently not easy to fix. This is completely useless except for showing people that perl is not bullet-proof.

sudo grub-install --root-directory=/media/ubuntu /dev/sda
2011-09-27 17:51:56
User: totti
Functions: sudo
Tags: grub boot fix
-2

From live CD mount(open) the Ubuntu installed drive.

Copy the location (press Ctrl+l, Ctrl+c ) eg: /media/ubuntuuuu

Open terminal (Apllication->accessories->terminal)

Type this:

sudo grub-install --root-directory=/media/ubuntuuuu /dev/sda

(replace /media/ubuntuuuu with what u got (ie paste))

Will show success message. Now reboot

host `hostname`
2009-02-18 05:48:29
User: rommelsharma
Functions: host
-2

This is a useful command that gives the hostname and the IP Address of your machine, on many OS. Tested on Linux and Solaris.

host command here is followed by `hostname`. Note the ` in the command is a back quote (or grave accent or back tic that usually shares the space with the ~ key). No other options are specified. See sample output.

wc -l `find . -name *.php`