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,605 results
host <domain> <nameserver name>
2009-09-29 18:58:28
User: DoGik
Functions: host
-3

Its very useful when you do not have control over name servers and need to check DNS configuration directly, right after change. You will not need to wait for DNS propagation to verify if all records were configured properly by vendors of name servers.

sudo /etc/acpi/sleep.sh sleep
2010-08-03 23:54:49
User: jmfork
Functions: sudo
Tags: sleep suspend
-3

It suspends to RAM: you always need your batteries for the RAM but it saves time as there is no need to slowly archive everything on your hard disk.

It works fine with me but if anyone has a nicer way, please contribute.

gpg -ab file.txt
gpg -ser 'myfriend@gmail.com' file.txt
2011-09-17 04:51:02
User: kev
Functions: gpg
Tags: GPG
-3

-s

Make a signature.

-e

Encrypt data.

-r

Encrypt for user id name.

curl sputnick-area.net/ua
2011-10-24 09:57:50
User: sputnick
Tags: curl headers
-3

That's useful when you're doing some web scraping http://en.wikipedia.org/wiki/Web_scraping and you're trying to test your possibly fake user-agent.

grep -H -r "string" ./* >> grep.txt
wget http://checkip.dyndns.org/ -q -O - | grep -Eo '\<[[:digit:]]{1,3}(\.[[:digit:]]{1,3}){3}\>'
launchctl load /Library/LaunchDaemons/<plist config filename>.plist
2011-02-01 17:02:49
User: frank514
-3

to unload Daemon, use: launchctl unload /Library/LaunchDaemons/.plist

(cd /source/dir ; tar cvf - .)|(cd /dest/dir ; tar xvpf -)
openssl rand -base64 1000 | tr "[:upper:]" "[:lower:]" | tr -cd "[:alnum:]" | tr -d "lo" | cut -c 1-8 | pbcopy
2009-12-29 17:18:25
User: _eirik
Functions: cut tr
-3

eliminates "l" and "o" characters change length by changing 'x' here: cut -c 1-x

cat file.txt | sendmail -F myname -f admin@mysite.com guest@guest.com
watch -n 1 cat /proc/net/wireless
2012-06-07 10:38:21
User: cantormath
Functions: cat watch
-3

Values will depend on the driver and the hardware specifics, so you need to refer to your driver documentation for proper interpretation of those values.

perl -e 'use Date::Calc qw(Today Week_Number); $weekn = Week_Number(Today); print "$weekn\n"'
cd <YOUR_DIRECTORY>; for i in `ls ./`; do tar czvf "$i".tar.gz "$i" ; done
2009-06-11 18:33:27
User: ElAlecs
Functions: cd tar
-3

Very simple and useful, you need to change the word "directory" for your directory

tar -zcvpf backup_`date +"%Y%m%d_%H%M%S"`.tar.gz `find <target> -atime +5 -type f` 2> /dev/null | parallel -X rm -f
2010-01-28 12:41:41
Functions: rm tar
-3

This deals nicely with files having special characters in the file name (space ' or ").

Parallel is from https://savannah.nongnu.org/projects/parallel/

alias whatismyip="wget -q -O - http://whatismyip.com/automation/n09230945.asp"
2009-10-30 15:42:52
User: gibboris
Functions: alias
-3

The preferred way for scripts (and easier to parse)

MyVAR=84; awk '{ print "'"$MyVAR"'" }'
tail /var/log/auth.log -n 100
UNIQUE_BY_MAC=$(ifconfig |grep eth0|awk '{ print strtonum("0x"substr($6,16,2)) }')
2010-06-01 17:34:43
User: rubo77
Functions: awk grep ifconfig
-3

gets the last number of the mac address to use it for other stuff

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.