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,925 results
yes n | cp something toSomeWhereElse
alias myip='curl -s http://checkrealip.com/ | grep "Current IP Address"'
for f in *;do case "$(echo $f|sed "s/.*\.\([a-z\.]*\)/\1/g")" in zip)unzip -qqo $f&&rm $f;;tar.gz|tar.bz2)tar xf $f&&rm $f;;rar)unrar e -o+ -r -y $f&&rm $f;;7z)7z e -qqo $f;;esac;done
2009-08-17 03:50:50
User: matthewbauer
-2

This will unarchive the entire working directory. Good for torrents (I don't know why they put each file into a seperate archive).

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --proxy-server=socks5://HOST:PORT
curl -Ls "http://support.dell.com/support/DPP/Index.aspx?c=us&cs=08W&l=en&s=biz&ServiceTag=$(dmidecode -s system-serial-number)"|egrep -i '>Your Warranty<|>Product Support for'|html2text -style pretty|egrep -v 'Request|View'|perl -pane 's/^(\s+|\})//g;'
2011-02-18 22:29:05
User: din7
Functions: egrep perl
-2

The dates in the output are Start Date, End Date, Days Remaining in warranty, respectively. This will only work if you are running it on a dell machine. You can substitute the dmidecode command with a service tag if you are not using a dell. Also, you have to either allow your user to run sudo dmidecode with no password or run this command as root.

curl -s http://checkrealip.com/ | grep "Current IP Address" | cut -d ' ' -f 4
:rm 1
_llines=100; while [ $_llines -gt 1 ]; do echo $_llines; _llines=$(($_llines-1)); done
2009-04-29 00:19:45
User: romulusnr
Functions: echo
-2

You've opened a terminal window and you've connected off to a remote host that didn't pick up your terminal size, and all your curses and paging apps are screwed up as a result. You need to quickly determine how many lines are in your current terminal view (to feed into "stty rows X").

diff -qr /dirA /dirB
cd $(find -inum inode_no)
2010-09-25 06:04:32
User: emacs
Functions: cd find
-2

First use ls -i to list files and directories with their inode number

Then if you want to change to one of the directories, replace inode_no with its inode then execute the command

mount -o auto -t ntfs /dev/hda1 /windows
2009-02-16 10:45:06
User: RonaldConco
Functions: mount
-2

if the command is successful , you will get no output - only if an error has occurred will there be output

video=$(ls /tmp | grep -e Flash\w*); ffmpeg -i /tmp/$video -f mp3 -ab 192k ~/ytaudio.mp3
find . -name '*.txt' | grep -v '\.lzma$' | xargs -n 1 lzma -f -v -3
rm **/*.htm
2010-11-25 17:28:55
Functions: rm
Tags: find rm
-2

expands through shell and not find

but may hits the limit of max argument size for rm

(thus: for f in **/*.htm;do rm $f;done

but then I prefer the find command ;)

for i in $(ls /the/path); do du -hs /the/path/$i; done
watch w
for domain in `cat list_of_domains.txt`; do echo $domain; whois $domain >> output.txt; done
2010-02-15 17:13:45
User: pathcl
Functions: echo whois
-2

Outputs multiple whois from a plain text file.

vim -p file1 file2 [...]
lynx -useragent=Opera -dump 'http://www.facebook.com/ajax/typeahead_friends.php?u=4&__a=1' |gawk -F'\"t\":\"' -v RS='\",' 'RT{print $NF}' |grep -v '\"n\":\"' |cut -d, -f2
cat /var/log/secure | grep smtp | awk '{print $9}' | cut -f2 -d= | sort | uniq -c | sort -n | tail
2009-03-30 15:49:54
User: empulse
Functions: awk cat cut grep sort uniq
-2

Searches /var/log/secure for smtp connections then lists these by number of connections made and hosts.

tcpdump -n -v tcp or udp or icmp and not port 22
cat file1.txt | uniq > file2.txt
wget -O - 'https://USERNAMEHERE:PASSWORDHERE@mail.google.com/mail/feed/atom' --no-check-certificate
2010-09-26 14:47:13
User: PLA
Functions: wget
-3

I use this command in my Conky script to display the number of messages in my Gmail inbox and to list the from: and subject: fields.

lspv
2012-09-13 15:20:06
User: kaushalmehra
Tags: hard disk
-3

The lspv command displays the information about the physical volume if the specific

physical volume name is specified. If you do not add flags to the lspv command, by default

all the available physical volumes are printed along with the following information:

* Physical disk name.

* Physical volume identifiers (PVIDs).

* The volume group, if any, that the physical volume belongs to or the label,if any,

locked with the lkdev command.

* The state of the volume group.

Active-When the volume group is varied on.

Concurrent-When the volume group is varied on in the concurrent mode.

Locked-When the physical volume is locked with the lkdev command.

****************************************************************************************

In the example, the iw406 system has two hard disks.

Phy disk name Phy vol identfrs (PVIDs) volume group State of Volumne group

hdisk0 00f6267c8a99c7b6 rootvg active

hdisk1 00f6267cb3746d01 appinstvg active

hdisk0 is mounted on volume group rootvg. hdisk1 is mounted on volume group appinstvg

find . -depth -type d -empty -exec rmdir -v {} \;