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,857 results
alias myip='curl -s www.wieistmeineip.de | egrep -o "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"'
sed 's/\b\(0*\)//g' filename
2009-03-24 20:19:42
User: alperyilmaz
Functions: sed
Tags: sed
1

Leading zeros might help correct sorting and they can be removed by sed after sorting

sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta' filename
2009-03-24 20:06:02
User: alperyilmaz
Functions: sed
Tags: sed
3

Does not necessarily require a file to process, it can be used in a pipe as well:

cat filename | sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta'

I don't remember where I copy/pasted this from, I wish I credited the original author

head -c $((<pw-lenght>-2)) /dev/urandom | uuencode -m - | sed -e '1d' -e '3d' | sed -e 's/=.*$//g'
2009-03-24 20:05:16
User: P17
Functions: head sed uuencode
-2

Replace < pw-length > with the desired password-length.

The password-length is not always correct, but wayne...

watch ethtool eth0
2009-03-24 20:03:25
User: israel
Functions: watch
0

verifry if link detected or no and speed of network.

mysql DATABASE -N -s -r -e 'SQL COMMAND'
2009-03-24 19:53:46
User: alperyilmaz
Tags: mysql
5

-N removes header

-s removes separator chars

-r raw output

After using these options, the MySQL ouptut can be used with pipes very easily

ps ax | grep <processname> | grep -v grep | awk '{print $1}' | sudo xargs kill -9
php -r 'echo strtotime("2009/02/13 15:31:30")."\n";'
2009-03-24 19:38:46
User: sudopeople
7

Most people know that you can run a PHP script from the command line like so:

php ./my_script.php

But sometimes I just want to run a quick bit of code, the PHP Command Line Interface allows me to do so with the -r option.

Requires package php5-cli

rpm -Va | grep -v "\.\.\.\.\.\.\.T"
cat -v -t -e
2009-03-24 19:29:03
User: alperyilmaz
Functions: cat
Tags: cat
4

Useful to detect number of tabs in an empty line, DOS newline (carriage return + newline).

A tool that can help you understand why your parsing is not working.

man -t man | lp
2009-03-24 19:08:07
User: icco
Functions: man
Tags: printing
4

man -t manpagename gives a postscript version of said man page. You then pipe it to ls, and assuming you have cups set up, it prints in your default printer.

echo -e "[client]\nuser = YOURUSERNAME\npassword = YOURPASSWORD" > ~/.my.cnf
2009-03-24 19:05:39
User: alperyilmaz
Functions: echo
Tags: mysql bash
0

The file .my.cnf located at user's home directory is used for mysql login. If this file exists, then

mysql -uYOURUSERNAME -pYOURPASSWORD database -e 'SOME SQL COMMAND'

can be replaced with

mysql database -e 'SOME SQL COMMAND'

It saves you from typing!

This is valid for mysqladmin and mysqldump commands as well.

/usr/sbin/arp -i eth0 | awk '{print $3}' | sed 1d
date -d "@$(find dir -type f -printf '%C@\n' | sort -n | sed -n "$(($(find dir -type f | wc -l)/2))p")" +%F
2009-03-24 18:48:49
User: allengarvin
Functions: date dir find wc
-1

I needed to get a feel for how "old" different websites were, based on their directories.

vimdiff foo.c <(bzr cat -r revno:-2 foo.c)
gs -q -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=test.pdf multipageproject.pdf
2009-03-24 17:14:46
User: iain
Functions: gs
3

Xsane produces PDFs that are too large - particularly multipage PDFs. This command compresses them. If you do not use A4, remove the -sPAPERSIZE flag.

tar -czf - * | ssh example.com "cat > files.tar.gz"
2009-03-24 17:02:02
User: migurski
Functions: ssh tar
5

I recently found myself with a filesystem I couldn't write to and a bunch of files I had to get the hell out of dodge, preferably not one at a time. This command makes it possible to pack a bunch of files into a single archive and write it to a remote server.

host google.com
2009-03-24 16:25:12
User: tommaso
Functions: host
1

host is a simple utility for performing DNS lookups. It is normally used to convert names to IP addresses and vice versa. When no arguments or options are given, host prints a short summary of its command line arguments and options.

bc
2009-03-24 16:19:12
User: haivu
Functions: bc
-2

bc is a wonderful calculator. Just type bc at the command line and have at it. Ctrl+D (or type quit) will get you out. This usage is just scratching the surface: bc can handle a mini scripting language, complete with variable, statements, loop, conditional statements and more. Do a man page on it to find out.

w
2009-03-24 16:03:28
User: haivu
-1

Short and sweet command. This command is also useful for other information such as what IP address a particular user logged in from, how long had they been logged in, what shell do they use.

find . -regex "[^.]*" -depth -empty -type d -mtime +1 -exec rmdir -v {} \;
rdate -s time-A.timefreq.bldrdoc.gov
bvi [binary-file]
2009-03-24 15:30:50
User: haivu
Tags: edit
-3

bvi is your vi for binary editing. If your system does not have it, you can get it from

http://bvi.sourceforge.net/

find / -nouser -o -nogroup -print
perl -e 'print "Hello World!", "\n";'