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,860 results
( cd SOURCEDIR && tar cf - . ) | (cd DESTDIR && tar xvpf - )
pax -r -s ',^/,,' -f file.tar
2009-06-26 19:10:57
User: res0nat0r
Functions: pax
Tags: tar
0

Don't have GNU tar installed that supports the redirect option (-C)? Use this.

find -L /proc/*/fd -links 0 2>/dev/null
2009-06-26 18:42:51
User: res0nat0r
Functions: find
Tags: du proc df
12

Oracle DBA remove some logfiles which are still open by the database and he is complaining the space has not been reclaimed? Use the above command to find out what PID needs to be stopped. Or alternatively recover the file via:

cp /proc/pid/fd/filehandle /new/file.txt
rsop.msc
2009-06-26 11:19:50
User: felix001
4

Type this into windows via run and it will display to you your complete policy for windows. This includes group policy, security policy and your active directory account (min password etc)....

www.fir3net.com

watch 'netstat -aniv'
netstat -lnp
ps aux | grep -v `whoami`
pdftk $* cat output $merged.pdf
echo "Hello World." | tee -a hello.txt
2009-06-26 00:55:59
Functions: echo tee
Tags: tee
1

When plumbers use pipes, they sometimes need a T-joint. The Unix equivalent to this is 'tee'. The -a flag tells 'tee' to append to the file, rather than clobbering it.

Tested on bash and tcsh.

man fetchmail | perl -ne 'undef $/; print $1 if m/^.*?(-k \| --keep.*)-K \| --nokeep.*$/smg'
2009-06-25 23:51:35
Functions: fetchmail man perl
0

Using perl, here, we grep the man page of fetchmail to find the paragraph starting with '-k | --keep' and ending before the paragraph starting with '-K | --nokeep'

echo "aplay path/to/song" |at [time]
2009-06-25 19:33:37
User: brausen
Functions: at echo
Tags: alarm
8

Set an alarm to starts in specific time.

sleep 5h && rhythmbox path/to/song
2009-06-25 19:15:19
User: becomingGuru
Functions: sleep
3

Sleep 5h and plays the song as a wake up alarm

gs -q -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=out.pdf a.pdf b.pdf c.pdf
2009-06-25 19:04:28
User: becomingGuru
Functions: gs
5

merge a.pdf b.pdf and c.pdf and create ./out.pdf

su - <user> -s /bin/sh -c "/bin/sh"
nmap -A -p1-85,113,443,8080-8100 -T4 --min-hostgroup 50 --max-rtt-timeout 2000 --initial-rtt-timeout 300 --max-retries 3 --host-timeout 20m --max-scan-delay 1000 -oA wapscan 10.0.0.0/8
2009-06-25 14:12:26
User: merkmerc
7

I've used this scan to sucessfully find many rogue APs on a very, very large network.

mstsc /w:1500 /h:900 /v:www.example.com
2009-06-25 14:01:42
User: merkmerc
1

Using a widescreen monitor, I often get annoyed that the RDP window is too high, or too narrow for what I want to display. In this example, I'm on a 1680 x 1050 display.

echo "-------------" >> nicinfo.txt; echo "computer name x" >> nicinfo.txt; ifconfig | grep status >> nicinfo.txt; ifconfig | grep inet >> nicinfo.txt; ifconfig | grep ether >> nicinfo.txt; hostinfo | grep type >> nicinfo.txt;
/usr/dt/bin/dtconfig -d
2009-06-25 09:32:37
1

With a full installation of Solaris 10, the graphical login and desktop will start by default. This command will disable that feature. To enable it again use: /usr/dt/bin/dtconfig -e

sudo /Applications/Utilities/Adobe\ Utilities.localized/Adobe\ Updater5/Adobe\ Updater.app/Contents/MacOS/Adobe\ Updater
2009-06-25 08:07:47
User: miccaman
Functions: sudo
Tags: Os X
-9

adobe updater keeps popping up. (normal update fails, probably due to insufficient rights)

(src: http://aricsblog.blogspot.com/2007/12/adobe-updater-crashes-on-mac-os-x-and.html)

ctrl + r
2009-06-25 06:51:38
User: Bluehive
9

Very handy and time-saving.

Do a 'ctrl+ r' on command prompt. You will see a "(reverse-i-search)`':" mark. Just type any sub-string of the command you want to search(provided you have used it sometime in the same session).

Keep on searching by repeatedly pressing ctrl+r. Press enter once you get the desired command string.

curl -v -k -u user:password "https://members.dyndns.org/nic/update?hostname=<your_domain_name_here>&myip=$(curl -s http://checkip.dyndns.org | sed 's/[a-zA-Z<>/ :]//g')&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
2009-06-24 17:00:15
User: din7
5

This is great if you are behind a router that does not support dynamic dns updates!

Example: AT&T u-verse gateway...

Put this in a script and run it as a cron job.

echo $numbers | sed "s/\( \|$\)/\n/g" | sort -nu | tr "\n" " " | sed -e "s/^ *//" -e "s/ $//"
2009-06-24 15:12:17
User: chickenzilla
Functions: echo sed sort tr
-1

You can replace "sort -nu" with "sort -u" for a word list sorted or "sort -R" for a random-sorted line

(edit: corrected)

mii-tool eth0
2009-06-24 08:43:55
User: flart
6

with 'mii-tool -w eth0' you can watch the interface for changes of the link status

echo "${STRING}" | tr '[A-Z]' '[a-z]' | awk '{print toupper(substr($0,1,1))substr($0,2);}'
2009-06-23 21:11:34
User: mohan43u
Functions: awk echo tr
Tags: awk tr
0

Helpful when we want to do mass file renaming(especially mp3s).

find . -depth -type d -exec du -s {} \; | sort -k1nr
2009-06-23 20:52:35
User: mohan43u
Functions: du find sort
Tags: sort find du
4

somewhat faster version to see the size of our directories. Size will be in Kilo Bytes. to view smallest first change '-k1nr' to '-k1n'.