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,587 results
site="http://gifbin.com/"; for i in $(wget -qO- "$site"random| sed -r "s/^.*(bin\/.+\.gif).*$/\1/m" | grep "^bin"); do wget -c "$site$i"; filename=`basename $i`; [ `identify $filename | wc -l` -gt 1 ] || rm -f $filename; done
2011-02-15 10:05:37
User: az
Functions: grep rm sed wc wget
-2

Download a bunch of random animated gifs from http://gifbin.com/

while x=0; do foo ; sleep 1 ; done
2012-07-11 13:22:21
User: eastwind
Functions: sleep
-2

repeat a command every X seconds , output show the creation of partition image using fsarchiver, each line show the size of the image.

pkill -U MYWIFE
2009-02-05 22:10:07
User: HansReiser
-2

Kills all processes owned by user MYWIFE (replace MYWIFE with username or ID of your choice)

(Thanks, porges, for the better command)

ssh -C -X user@remotehost gui_command
2009-05-21 17:52:24
User: sharfah
Functions: ssh
-2

Run GUI apps on another machine remotely through SSH.

-C is for data compression and -X enables X11 forwarding.

n=$RANDOM$RANDOM$RANDOM; let "n %= 10000000000"; echo $n
cat /proc/acpi/battery/*/state
find -maxdepth 1 -type d | while read dir; do echo $dir; echo cmd2; done
purple-remote "msn:getinfo?screenname=xxx"
cd "~/Music/iTunes/iTunes Media/Mobile Applications";ls > filepath
sudo hal-get-property --udi /org/freedesktop/Hal/devices/computer --key 'system.formfactor'
files -type f | xargs -n100 | while read l; do mkdir $((++f)); cp $l $f; done
2011-02-15 23:15:16
User: flatcap
Functions: cp mkdir read xargs
-2

Take a folder full of files and split it into smaller folders containing a maximum number of files. In this case, 100 files per directory.

find creates the list of files

xargs breaks up the list into groups of 100

for each group, create a directory and copy in the files

Note: This command won't work if there is whitespace in the filenames (but then again, neither do the alternative commands :-)

curl icanhazip.com
2010-06-14 18:47:11
User: pykler
-2

With a lolcat favicon if you access it from your browser

ps -a |grep cat |wc -l
rename foo bar directory/filename
2011-05-04 22:29:11
User: hexram
Functions: rename
-2

rename command in my system -Fuduntu running 2.6.38 Linux Kernel- is an ELF 64-bit LSB executable, not a Perl script. man page for rename command shows syntax as "rename from to where" (or something like that), so I am doing just what I have been told...

echo "ls" > script.bash; gpg -c script.bash; cat script.bash.gpg | gpg -d --no-mdc-warning | bash
2013-03-10 09:34:12
User: betsubetsu
Functions: cat echo gpg
-2

echo "ls" > script.bash;

This is my script, a simple 'ls'.

gpg -c script.bash;

Here I encrypt and passord-protect my script. This creates file script.bash.gpg.

cat script.bash.gpg | gpg -d --no-mdc-warning | bash

Here I open file script.bash.gpg, decrypt it and execute it.

perl -lpe'1 while s/^([-+]?\d+)(\d{3})/$1.$2/'
for k in *.png; do convert $k -crop <width>x<high>+<cropwidth>+<cropthigh> <newpath>/$k; done
2011-11-14 17:04:15
User: mrehqe
-2

Crop several images by imagemagik's convert command. substitute , ,, with pixel value and with a different existent directory.

tail -f file | egrep --color=always $\|PATTERN
2009-10-15 13:08:30
User: sitaram
Functions: egrep file tail
Tags: color
-2

but you can't see the colors in that sample output :(

for i in `mailq | awk '$6 ~ /^frozen$/ {print $3}'`; do exim -Mrm $i; done
2010-01-13 21:28:45
User: rjamestaylor
Functions: awk
Tags: bash awk exim
-2

Although Exim will purge frozen (undeliverable) messages over time, the command "exim -Mrm #id#" where #id# is a particular message ID will purge a message immediately. Being lazy, I don't want to type the command for each frozen message, so I wrote the one-liner to do it for me.

umount -l /media/foo
2009-02-16 02:51:49
User: nomad
Functions: umount
-2

Will unmount a mount that has already dropped but is locked by a process.

exipick -zi | xargs exim -Mrm
echo "alias sudo=\"aplay annoyingsoundfile.ogg\"" >> .bash_aliases
cut -f1 -d"<TAB>"
for i in $(ls *.mp3); do mplayer $i && echo "delete it? [y/n]" && read trash && if [ "$trash" == "y" ]; then rm $i; fi; do
2013-12-23 20:09:56
User: wibbel4
Functions: echo ls read rm
-2

Old drive with lots of music or unsorted drive? This command will play all mp3 files in a folder and after playing one song or pressing q, it will ask you if you want to delete the file.

brew update && brew install `brew outdated`