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,487 results
while true ; do du -sk testfile ; sleep 10 ; done
2009-08-14 11:39:52
User: Solaris
Functions: du sleep true
-2

This command produces the output of "du -sk testfile" in every 10 seconds. You can change the command to be whatever you want.

for F in $(find ./ -name "*.tgz") ; do tar -tvzf $F ; done
2009-11-11 00:50:52
User: alchandia
Functions: find tar
Tags: tar
-2

The magic is performed by the parameter -t

ls | sed 's,\(.*\),"\1",'
2010-08-17 14:27:27
User: randy909
Functions: ls sed
-2

I had a file named " " (one space) and needed a way to see what the real filename was so I could remove it. sed to the rescue.

alias sshdo='ssh -q -t root@localhost -- cd $PWD \&\& sudo'
2010-10-20 22:33:22
User: darkfader
Functions: alias cd
Tags: sudo su ssh-agent
-2

Run program as root by SSH key forwarding instead of sudoers.

Put this alias line in .bashrc or wherever you like. Alias arguments might need extra escaping.

You might wonder about security. But you'd block out root login as much as possible of course. In sshd_config you put this:

PermitRootLogin no

Match Address 127.0.0.1

  PermitRootLogin without-password

xinit $(which awesome) -- /usr/bin/Xephyr :5 -once -fullscreen -ac -keybd "ephyr,,,xkbmodel=pc105,xkblayout=it,xkbrules=evdev,xkboption="
2012-11-03 00:54:33
User: hute37
Functions: which
Tags: awesome
-2

alternatives:

xinit $(which gnome-awesome-session)

with cat /usr/local/bin/gnome-awesome-session:

#!/bin/bash

exec gnome-session --session awesome "$@"

following: http://awesome.naquadah.org/wiki/Quickly_Setting_up_Awesome_with_Gnome

note: in ubuntu 12.10 a probable Xephyr recent bug rejects keybd option ...

mplayer -shuffle $HOME/music/* $HOME/Dropbox/Music/*/* $HOME/Dropbox/Music/*/*/* etc. >> /dev/null 2>&1
for f in *.png; do convert $f -resize 852x480 $f; done
2013-12-15 11:28:07
User: egeoffray
-2

Resize all png in the current folder.

Warning: no copy. Make sure you have a copy of the originals

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
ssh-add ~/.ssh/KEY_PAIR_NAME.pem
2012-11-03 02:59:52
User: brockangelo
Functions: ssh ssh-add
Tags: ssh EC2
-2

This command adds your pem key to SSH so that you no longer have to manually specify it when connecting to EC2 instances.

# you can do this:

ssh ec2-instance.amazonaws.com

# instead of this:

ssh -i ~/.ssh/KEY_PAIR_NAME.pem ec2-instance.amazonaws.com

./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