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,605 results
10,30,50 * * * * ping -q -c1 -w3 192.168.0.14 | grep '1 received' - || env DISPLAY=:0 xeyes
2012-02-06 09:40:11
User: knoppix5
Functions: env grep ping
Tags: ping host crontab
-2

Every 20 minutes ping host with IP address 192.168.0.14. If it's not 'alive' or not reachable, then display something eye-catching (here xeyes) on the desktop.

Hint for newbies: edit crontab with

crontab -e
./poweriso extract $USER/file.daa / -od $USER/file_extracted
2009-02-15 23:19:40
User: brettalton
-2

.daa is a non-standard disk image format that can not be read by any other program. This is how you can extract the files though.

PowerISO binary for Linux: http://www.poweriso.com/poweriso-1.3.tar.gz

"This is a free utility for linux which can extract, list, and convert image files (including ISO, BIN, DAA, and other formats). Type " poweriso -? " for detailed usage information. File Size: 278KB"

clamscan -ir --bell ~user/
2009-05-21 13:09:31
-2

Scan for viruses, recursively and print only infected files, with bell sound. Clamscan is part of clamav package. Tested on Debian.

wget -qO - http://cfaj.freeshell.org/ipaddr.cgi
curl http://whatismyip.org
[Ctrl+u]
ls . | xargs file | grep text | sed "s/\(.*\):.*/\1/" | xargs gedit
for i in 192.168.1.{1..254} ; do if ping -c1 -w1 $i &>/dev/null; then echo $i alive; fi; done
git last commit on a file.
tar -cf - /etc | tar -xf - -C </destination/folder>
sudo sync && sudo echo 3 | sudo tee /proc/sys/vm/drop_caches
2012-03-17 08:27:58
User: StephenJudge
Functions: echo sudo sync tee
Tags: memory cache
-2

"That's it. Not much to see here. The first command writes any cache data that hasn't been written to the disk out to the disk. The second command tells the kernel to drop what's cached. Not much to it. This invalidates the write cache as well as the read cache, which is why we have the sync command first. Supposedly, it is possible to have some cached write data never make it to disk, so use it with caution, and NEVER do it on a production server. You could ... but why take the risk?

As long as you are running a post 2.6.16 kernel,..."

Source: http://ubuntuforums.org/showpost.php?p=3621283&postcount=1

cal 04 2012 | awk 'NF <= 7 { print $7 }' | grep -v "^$" | tail -1
2012-05-03 16:57:45
User: javidjamae
Functions: awk cal grep tail
-2

This is a little trickier than finding the last Sunday, because you know the last Sunday is in the first position of the last line. The trick is to use the NF less than or equal to 7 so it picks up all the lines then grep out any empty lines.

free -m | awk '/Swap/ {print $4}'
2009-09-02 11:46:17
User: voyeg3r
Functions: awk free
-2

simple way to show free swap

ls -a | egrep "^\.\w"
2009-11-11 18:19:56
User: kulor
Functions: egrep ls
Tags: egrep ls dotfiles
-2

trying to copy all your dotfiles from one location to another, this may help

echo "X-Facebook: from zuckmail ([MTI3LjAuMC4x])" | cut -d \[ -f 2 | cut -d \] -f 1 | openssl base64 -d
2010-05-09 00:46:28
User: IsraelTorres
Functions: cut echo
-2

Currently Facebook has updated their headers to display 127.0.0.1 but if you have saved e-mails from messages and FB related mail you can still reveal the IP. :)

Tested on Mac OS X 10.6.3

open -a Finder <path>
cd
mount -t msdos /dev/fd0 /mnt/floppy
2009-12-10 06:46:53
User: eastwind
Functions: mount
-2

-t option tells the system to look for a msdos filesystem

The /dev/fd0 is your floppy drive ( This may be different for you check /dev folder to confirm)

/mnt/floppy is the point where you want to mount the device to

rm -fr `find . -name Thumbs.db`
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