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,491 results
ifconfig eth0 | grep 'HWaddr' | awk '{print $5}' | tr 'a-z' 'A-Z' | sed -e 's/://g'
2010-06-26 05:35:03
User: minigeek
Functions: awk grep ifconfig sed tr
-3

This will get the mac address of the eth0 and change lowercase to uppercase.

The sed command removed the colons.

lame rec01.wav rec01.mp3
sudo sox <file name>.wav -r 8000 <file name>.gsm
du -sh *
ls -l `ls -l |awk '/^l/ {print $8}'`
2009-11-23 16:02:18
User: yooreck
Functions: awk ls
-3

ls -l may vary depending on operating system, so "print $8" may have to be changed

sudo sox <file name>.wav -r 8000 <file name>.gsm
TODAY=`date +"%b %d"`;ls -l | grep "$TODAY" | awk '{print $9}'
copy(){ cp -v "$1" "$2"&watch -n 1 'du -h "$1" "$2";printf "%s%%\n" $(echo `du -h "$2"|cut -dG -f1`/0.`du -h "$1"|cut -dG -f1`|bc)';}
curl -s http://urlxray.com/display.php?url=http://tinyurl.com/demo-xray | grep -o '<title>.*</title>' | sed 's/<title>.*--> \(.*\)<\/title>/\1/g'
2010-09-30 10:25:18
User: karpoke
Functions: grep sed
Tags: sed grep curl
-3

We can put this inside a function:

fxray() { curl -s http://urlxray.com/display.php?url="$1" | grep -o '<title>.*</title>' | sed 's/<title>.*--> \(.*\)<\/title>/\1/g'; }; fxray http://tinyurl.com/demo-xray
tr -d '\001'-'\011''\013''\014''\016'-'\037''\200'-'\377' < filein > fileout
tar -C <source_dir> -cf . | tar -C <dest_dir> -xf -
ifconfig | grep "inet\ " | grep -v "127.0" | sed -e 's/inet\ addr://g' | sed -e 's/Bcast:/\ \ \ \ \ \ \ /g' | cut -c 1-29 | sed -e 's/\ //g'
cd $(ls -1t --color=never | head -1)
ls -la | grep $(date +%Y-%m-%d) | egrep -v -e '\.{1,2}' | sed "s/.*\:[0-9]\{2\} \(.\+\)$/\\1/g"
sudo iptables-save > /etc/iptables.up.rules
2009-08-19 14:55:05
User: kamiller
Functions: iptables-save sudo
-3

Stores the currently active iptables rules to a file that will be applied upon reboot

find . -name "*.EXT" | xargs grep -n "TODO" | wc -l
sed -i '/Centos/d' VirtualBox.xml
2009-05-05 13:03:55
Functions: sed
-3

Simple but useful command, I use this for purge an hard disk entry in Virtualbox registry file (is in ~user/.Virtualbox) that persist if I erase a Virtual Machine, so I need to delete it manually.

no untag
2010-03-26 02:45:32
User: rootgeek
Tags: foundry
-3

'no untag' is applied to _all_ ports under the default VLAN. Otherwise the default VLAN runs untagged over all physical ports. Pretty good idea to 'prune' your VLANs and define which ones pass over and across trunks that carry the default VLAN traffic.

cal -3
2009-04-02 17:40:38
User: haivu
Functions: cal
Tags: PIM
-3

the -3 show the previous, current, and next month.

ls *.wav | while read f; do lame "$f" -o "$(echo $f | cut -d'.' -f1)".mp3; done;
rstp priority 0
2010-03-26 02:51:54
User: rootgeek
Tags: foundry
-3

This is how you make sure that ports in a VLAN remain, root ports. Typically, you would use this command on all your Core-1 switch VLAN ports, and then use 'rstp priority 1' on all your Core-2 switches. This is if you have a dual L3 core that is.

rm !(*.txt)
aaa authentication login default local tacacs+
2010-03-26 02:58:03
User: rootgeek
Functions: login
Tags: foundry
-3

You need all those commands, in the sample output. I had some of this, but had to play, add remove, type random stuff like a monkey to finally get this working (clearly those IP's are fake to protect the guilty, and so is the key).

ntfsclone
2011-07-02 17:37:19
User: 0disse0
Tags: windows ntfs
-3

Although not frequently used, it is possible to clone an NTFS partition to an image file and, where necessary, restore the image to another partition. This command is useful, for example, if we want to keep a backup copy of our Windows installation, or in a corporate environment to install or repair a Windows of one or more computers. For the command syntax is refer to the documentation (man ntfsclone)

show optic <slot #>
2010-03-26 03:07:22
User: rootgeek
Tags: foundry
-3

Okay, Jimmy, the command 'optical-monitor' is needed within the global config. for this command to work (and if supported by your licsense: yada yada, blah, blah). But, like its mad PHAT Kid, you dig? Basically, a Foundry/Brocade switch is reading the Laser light levels just like those Fiber test kits from Owl that cost 4k. I know, I also find it hard to contain myeself ;-) No really.....