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,859 results
for dir in $(ls); do du -sk ${dir}; done
2009-03-24 13:42:55
User: morlockhq_
Functions: dir du
-15

Sometimes you want to know the summary of the sizes of directories without seeing the details in their subdirectories. Especially if it is going to just scroll off the screen. This one liner summarizes the disk usage of any number of directories in a directory without giving all the details of whats happening underneath.

find -iname '*.flac' | sed 's:/[^/]*$::' | uniq
2009-03-24 13:26:31
User: ar
Functions: find sed
-2

Run this in your music folder, or give the path directly after "find".

The sed pattern filters away the basename.

xvidcap --file filename.mpeg --fps 15 --cap_geometry 1680x1050+0+0 --rescale 25 --time 200.0 --start_no 0 --continue yes --gui no --auto
2009-03-24 08:49:15
User: tristan_ph
Functions: yes
Tags: xvidcap compiz
4

That will capture 200 seconds of video at fullscreen 1680x1050 resolution, but scaled down 25 percent, with 15 frames per second.

http://fusioncast.blogspot.com/2007/09/infobyte-how-i-record-my-desktop.html

cat schema.sql data.sql test_data.sql | mysql -u user --password=pass dbname
2009-03-24 08:39:40
User: tristan_ph
Functions: cat
Tags: mysql cat
-1

Be aware of using the --password argument as it will appear your password in plain text on the screen. You may use -p argument instead, it will prompt you to enter you password in hidden mode.

curl http://domain.com/file.tar.gz | tar zx
for i in $(pgrep -v -u root);do kill -9 $i;done
2009-03-24 02:54:52
User: lostnhell
Functions: kill
1

explanation:

grep -- displays process ids

-v -- negates the matching, displays all but what is specified in the other options

-u -- specifies the user to display, or in this case negate

The process loops through all PIDs that are found by pgrep, then orders a forced kill to the processes in numerical order, effectively killing the parent processes first including the shells in use which will force the users to logout.

Tested on Slackware Linux 12.2 and Slackware-current

for f in `jot - 0 50 5` ; do ping -c 1 -m 50 10.0.2.$f ; done
2009-03-23 23:51:18
User: chinkshady
Functions: ping
-5

Say you need to ping every 5th IP address on your network .. this will give you a way of doing that.

jot can also do counting ... like

jot 4

1

2

3

4

download from http://oreilly.com/catalog/upt2/examples/#jot or fins athena-jot in rpm format

while true; do date; sleep 1; done
2009-03-23 22:44:59
User: cbetts
Functions: sleep
0

Handy if all you have is a console session or tty.

nmap 192.168.0-1.0-255 -sP
2009-03-23 22:19:05
4

Depending on the network setup, you may not get the hostname.

find ./ -mtime -5 | xargs rm -f
curl -Is slashdot.org | egrep '^X-(F|B|L)' | cut -d \- -f 2
fuser -nu tcp 3691
lsof -P | grep ':3000'
cp --parents /source/file /target-dir
2009-03-23 18:35:15
User: bitmage
Functions: cp
6

The --parents option will cause cp or mkdir to automatically create the parent directory structure.

mkdir --parents /one/two/three/dir

will create /one, /one/two, and /one/two/three as needed before creating dir. cp will copy files with their full directory structure into the target directory with this option.

Thanks to Peter Leung at:

http://linuxcommando.blogspot.com/2007/11/use-of-parents-flag-in-mkdir-and-c.html

which has good examples of usage.

kill -9 `ps -u <username> -o "pid="`
kill -9 $(pidof process)
CTRL + e
CTRL + a
for i in `find . | grep jar$`; do echo $i; jar tvf $i | grep 'search-string'; done;
ps aux | grep 'httpd ' | awk {'print $2'} | xargs kill -9
convert -colors 256 -resize 16x16 face.jpg face.ppm && ppmtowinicon -output favicon.ico face.ppm
2009-03-23 15:00:13
User: medina
Tags: ImageMagick
14

Create a favicon suitable for use on your web site. Note: ppmtowinicon is part of libpbm, not ImageMagick.

for f in *.mp3 ; do lame --mp3input -b 128 "$f" ./resamp/"$f" ; done
2009-03-23 14:39:14
User: jjclarkson
Tags: audio
4

This will lower the quality of mp3 files, but is necessary to play them on some mobile devices.

ffmpeg -i file.flv -r 15 -b 128k -s qcif -acodec amr_nb -ar 8000 -ac 1 -ab 13 -f 3gp -y out.3gp
2009-03-23 14:30:45
User: jjclarkson
Tags: video ffmpeg
5

Download YouTube videos as .flv and convert them to .3gp for your mobile phone.

find . -name *.php | xargs grep -i -n 'TERM'
convert -colorspace gray face.jpg gray_face.jpg
2009-03-23 14:18:04
User: medina
Tags: ImageMagick
4

Use ImageMagick to create a "black and white" copy of an image.