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,610 results
screen -x `screen -ls | grep Detached | cut -c -10`
2012-03-01 14:13:09
User: peter4512
Functions: cut grep screen
Tags: gnu screen
-3

I alias this as "tach":

alias tach='screen -x `screen -ls | grep Detached | cut -c -10`'

If you have several detached sessions it will just grab the first one. If you're running nested screens you can open new outer windows and run tach repeatedly to grab all the detached sessions into that one.

ips(){ for if in ${1:-$(ip link list|grep '^.: '|cut -d\ -f2|cut -d: -f1)};do cur=$(ifconfig $if|grep "inet addr"|sed 's/.*inet addr:\([0-9\.]*\).*/\1/g');printf '%-5s%-15s%-15s\n' $if $cur $(nc -s $cur sine.cluenet.org 128 2>/dev/null||echo $cur);done;}
2009-08-07 10:04:46
User: frozenfire
Functions: cut echo grep ifconfig link sed
-3

Gets the internal and external IP addresses of all your interfaces, or the ones given as arguments

ls
kudzu -p
2009-05-12 10:34:59
Functions: kudzu
-3

Kudzu is available on CentOS, used for configuring and detecting new hardware device installed, is also usefull for device listing.

curl --basic --user username:password --data status="Twitter from commandline with curl" https://twitter.com/statuses/update.xml
2010-07-06 05:25:51
User: emacs
-3

--basic --user username:password

This will authenticate your Twitter username and password

--data status=""

Send data to the API with POST HTTP form.

lsof | grep 'DEL.*lib' | cut -f 1 -d ' ' | sort -u
2011-05-30 20:45:58
User: leenucks
Functions: cut grep sort
-3

Useful after a complete system update (without a new kernel) when you want to know, which processes need to be restarted

dd if=/dev/zero of=/fs/to/fill/dummy00 bs=8192 count=$(df --block-size=8192 / | awk 'NR!=1 {print $4-100}')
2009-12-03 15:20:18
User: arcege
Functions: awk dd df
Tags: dd df
-3

For disk space constraint testing. Leaves a little space available for creating temp files, etc. Easily free up the used disk space again by deleting the dummy00 file. Can tailor the testing by building smaller 'blocks' to suit the needs of the testing.

WARNING: do not do this to the '/' (root) filesystem unless you know what you are doing... on some systems it could crash the OS.

chmod -R u=rwX,go=rX .
!!
2009-07-16 08:07:35
User: Blackbit
-3

I don't know why this ain't written as simply as it is. I always see it's just used as parameter, like: vi `!!`

But i use it to repeat a command, as i always work on several shells and check the result of one shell on a second.

alias agi="sudo apt-get install" #package_names
2009-05-14 03:31:47
Functions: alias
-3

these are some aliases you can use in bashrc to shorten the amount of typing needed to use apt-get, also can be used as reference if you can't remember alot of commands or command parameter variations,etc...

Please comment with more apt-get aliases if I missed any, thx

geoip() { lynx -dump "http://www.geoiptool.com/en/?IP=$1" | sed -n '/Host Name/,/Postal code/p' ; }
2011-02-04 14:12:02
User: vando
Functions: sed
-3

Shows you the geolocation of an IP address.

response.headers['Cache-Control'] = 'public, max-age=60';
2011-07-11 23:35:36
User: evandrix
-3

possible options:

* Varnish

* Squid in reverse proxy mode

* Django's cache framework

* rack-cache

* or CDN, like Akamai

(Command too long..See sample Output..)
2009-06-14 20:34:37
User: mohan43u
Tags: bash sed echo tr od
-3

curl doesn't provide url-encoding for 'GET' data, it have an option '--data-urlencode', but its only for 'POST' data. Thats why I need to write down this commandline. With 'perl', 'php' and 'python', this is one liner, but just I wrote it for fun. Works in Ubuntu, will work in all linux varients(I hope it will work in unix varients also).

ssh-copy-id [-i [identity_file]] [user@]machine
for i in ./*.$1; do mv "$i" `echo $i | tr ' ' '_'`; done for i in ./*.$1; do mv "$i" `echo $i | tr '[A-Z]' '[a-z]'`; done for i in ./*.$1; do mv "$i" `echo $i | tr '-' '_'`; done for i in ./*.$1; do mv "$i" `echo $i | tr -s '_' `; done
export PATH=$PATH:`pwd`
2011-02-05 06:29:54
User: YogiBare
Functions: export
-3

This will temporarily add the current directory to your $PATH. Allowing you to execute from that directory for the duration of the session.

function encode4phone() { ffmpeg -acodec libamr_nb -vcodec h263 -i "$1" -s qcif -b 200k -ac 1 -ab 7.4k -ar 8000 "$1.3gp" }
tar cvf - /src | ( cd /dest ; tar xvf - )
2011-09-22 15:35:24
User: a8ksh4
Functions: cd tar
-3

This is how I've done it in the past

echo -e "aa\nbb\ncc\ndd\n123" | sed -e :a -e "/$/N; s/\n/;/; ta"
ps ho command $$
echo $SHELL
tar -zcps <dir> -X <(find <dir> -type f -mtime -<days>) |ssh user@backuphost tar -xzpsC /data/bkup
2009-02-12 22:31:58
User: zb
Functions: find tar
-3

due to bug can not comment

opendiff <file1> <file2>
2009-06-16 03:22:52
User: claytron
-3

This command will open up the two files in FileMerge on OS X. You can also compare two directories.

opendiff directory1 directory2

NOTE: FileMerge is a part of the OS X Developer Tools, available on the install disc.

rsync --daemon --port 9999 --no-detach -v --config .rsyncd.conf
2011-09-22 20:48:31
User: pykler
Functions: rsync
-3

An example config file is placed in the sample output along with the command line call to use it.

The rsync daemon here is setup on the destination, thus requiring the read only = false flag. Also it uses uid and gid of root, change as required.

exec 3<>/dev/tcp/whatismyip.com/80; echo -e "GET /automation/n09230945.asp HTTP/1.0\r\nHost: whatismyip.com\r\n" >&3; a=( $(cat <&3) ); echo ${a[${#a[*]}-1]};