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,586 results
awk '{total+=$0}END{print total}' file
find . -type f -exec ls -s {} \; | sort -n -r | head -5
python -c "import platform; print platform.node()"
paste -sd'+' file|bc -l
for i in $(seq 300) ; do ethtool -s eth0 autoneg on ; sleep 2 ; done
2010-10-31 18:15:54
User: christian773
Functions: seq sleep
-3

use this comand to see which switch port your network interface is using.

but remind, there is no network traffic for 10 minutes or how long you run the comand.

if you start the comand via ssh, port will come up again after the "for loop" has endet

echo "1+2+3+4" | bc
2011-02-24 03:08:00
User: twjolson
Functions: echo
-3

Works for any mathematical operation, even converting numbers from one base to another.

schtasks /delete /tn * /f
tac [FILE]
netstat -l -p --tcp | egrep -e 'www.*[0-9]{3,4}\/(apache2|httpd)' | awk '{print$7}'
pgrep -u username php5-fcgi | xargs kill -9
git-createrepo() { repos_path='/srv/git/'; mkdir $repos_path$1; cd $repos_path$1; git init --bare; echo "Repository location: ssh://$USER@`cat /etc/HOSTNAME``pwd`"; cd -; }
2013-05-09 21:44:24
User: batandwa
Functions: cd echo init mkdir
Tags: git
-3

Creates a git repository in a predefined location.

find /Users/jpn/.ievms/ -type f -print0| xargs -0 du -sh
2013-10-16 09:54:19
Functions: du find xargs
-3

When you do a ls -1 | xargs rm it wouldn't workd because those files have spaces. So you must use

find -print0 and xargs -0

for f in `find ./ -name "*.zip"` ; do p=`pwd`; d=`dirname $f`; cd $d; b=`basename $f`; unzip $b; cd $p; done
2009-05-30 03:42:53
User: packetloss
Functions: cd
Tags: find unzip
-3

unzips all zip files in any subdirectory under the current directory. The zip files are unzipped in their respective subdirs

du -hs /example/folder/
lsb_release -a
tar -cf - file1 dir1/ dir2/ | md5sum
2014-04-17 14:33:44
User: snipertyler
Functions: tar
-3

Doesn't create a file

Make sure to list the files / directories in the same order every time.

sudo dpkg -P $(dpkg -l | grep -i adobeair)
cat /proc/cpuinfo
apt-show-versions -u
2009-02-06 17:56:13
User: cowholio4
Functions: apt
-3

apt-show-versions is a program that shows what packages in the system may be updated and several useful information. The -u option displays a list of upgradeable packages:

From: http://www.debian.org/doc/manuals/apt-howto/ch-helpers.en.html

mysql -? | grep ".cnf"
2011-04-02 15:45:52
User: DarkSavant
Functions: grep
Tags: mysql
-3

This will show the locations, in order of preference, that MySQL will look for a configuration file

> [filename]
2011-05-18 14:59:02
User: bbbco
-3

Ever need to erase the contents of a file and start over from scratch? This easy command allows you to do so. Be warned! This will immediately erase all the contents of your file and start you over from scratch (i.e. your file will be at 0 bytes, like if you touch a file).

echo "string" | sed -e 's/.*match1//' -e 's/match2.*$//'
2009-04-01 15:01:27
User: P17
Functions: echo sed
-3

But who knows to delete the rest of the lines?

I want only "string".

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