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,951 results
PS3="Enter a number: "; select f in *;do $EDITOR $f; break; done
2009-09-10 06:04:42
User: haivu
Tags: bash
8

This command displays a simple menu of file names in the current directory. After the user made a choice, the command invokes the default editor to edit that file.

* Without the break statement, the select command will loop forever

* Setting the PS3 prompt is optional

* If the user types an invalid choice (such as the letter q), then the variable $f will become an empty string.

* For more information, look up the bash's select command

awk 'length>72' file
2009-09-10 05:54:41
User: haivu
Functions: awk
Tags: awk
16

This command displays a list of lines that are longer than 72 characters. I use this command to identify those lines in my scripts and cut them short the way I like it.

exiftool -DateTimeOriginal='2009:01:01 02:03:04' file.jpg
gcc -x c -o /tmp/out - -lgmp <<< '#include <stdlib.h> ... SEE SAMPLE OUTPUT FOR FULL COMMAND
2009-09-10 02:10:46
User: hank
Functions: c++ gcc
-5

It's hard to beat C. This is just slightly faster than the bc version on my machine.

real 0m26.856s

user 0m25.030s

sys 0m0.024s

Requirements: libgmp headers, gcc.

for i in `ls`;do avidemux --video-codec Xvid4 --load $i --save $i.mp4 --quit; done
2009-09-10 01:38:42
User: gean01
5

Using avidemux to convert multiple files that are in the folder where the command was executed.

man bash | col -b
2009-09-10 00:45:27
User: suxer
Functions: bash col man
-11

Display man page in plain text

help
2009-09-10 00:43:31
User: suxer
-7

for bash commands don't use man use help

dd if=/dev/zero of=/dev/fd0 bs=512 count=1
2009-09-09 23:43:22
User: andrew112358
Functions: dd
2

Overwrites the boot sector. Since this doesn't overwrite any data, you can usually recover by re-creating the partition table exactly the same as before you zeroed it. This can also help sometimes if you install a new drive in a Windows machine which can't read it.

curl -u username --silent "https://mail.google.com/mail/feed/atom" | perl -ne 'print "\t" if /<name>/; print "$2\n" if /<(title|name)>(.*)<\/\1>/;
2009-09-09 23:25:05
User: suxer
Functions: perl
-5

notice what happens when there is more than one unread message in a thread...

also people please dont hardcode the password when you use curl. Leave it out and curl will ask you when it runs. Please...?

iptables -t nat -A POSTROUTING -p tcp --dport 25 -j SNAT --to-source IP_TO_ROUTE_THROUGH
svn propset svn:ignore "*" tool/templates_c; svn commit -m "Ignoring tool/templates_c"
2009-09-09 19:10:03
User: lawrence
5

This command allow you to ignore certain directories on SVN commands, like SVN STATUS. It is sad see a lot of temporary files from templates_c for each "svn status", no? ;-)

This works only on directories under revision control.

cat /var/lib/dpkg/info/*.list > /tmp/listin ; ls /proc/*/exe |xargs -l readlink | grep -xvFf /tmp/listin; rm /tmp/listin
2009-09-09 18:09:14
User: kamathln
Functions: cat grep ls readlink rm xargs
Tags: Debian find dpkg
11

This helped me find a botnet that had made into my system. Of course, this is not a foolproof or guarantied way to find all of them or even most of them. But it helped me find it.

explorer .
ack -ai 'searchterm'
screen -x
2009-09-09 11:30:56
User: flart
Functions: screen
5

Force the user you want to watch doing things into doing his things in a screen session. Then simply attach yourself to that session with the command shown above.

Works only if you are on the same machine, of course

xdg-open .
2009-09-09 07:20:32
User: karpoke
Tags: xdg-open
2

Opens a file or URL in the user's preferred application.

echo -e "${PATH//://\n}" >/tmp/allpath; grep -Fh -f /tmp/allpath /var/lib/dpkg/info/*.list|grep -vxh -f /tmp/allpath >/tmp/installedinpath ; find ${PATH//:/ } |grep -Fxv -f /tmp/installedinpath
2009-09-09 05:33:14
User: kamathln
Functions: echo find grep
Tags: Debian dpkg PATH
0

OS: Debian based (or those that use dpkg)

Equivalent to doing a dpkg -S on each file in $PATH, but way faster.

May report files generated though postinstall scripts and such. For example . It will report /usr/bin/vim .. which is not not a file installed directly by dpkg, but a link generated by alternatives hooks

gnome-open .
ssh root@`for ((i=100; i<=110; i++));do arp -a 192.168.1.$i; done | grep 00:35:cf:56:b2:2g | awk '{print $2}' | sed -e 's/(//' -e 's/)//'`
2009-09-09 04:32:20
User: gean01
Functions: arp awk grep sed ssh
8

Connect to a machine running ssh using mac address by using the "arp" command

echo src::${PATH} | awk 'BEGIN{pwd=ENVIRON["PWD"];RS=":";FS="\n"}!$1{$1=pwd}$1!~/^\//{$1=pwd"/"$1}{print $1}'
2009-09-09 04:03:46
User: arcege
Functions: awk echo
Tags: awk echo PATH
-2

Removes trailing newline; colon becomes record separator and newline becomes field separator, only the first field is ever printed. Replaces empty entries with $PWD. Also prepend relative directories (like ".") with the current directory ($PWD). Can change PWD with env(1) to get tricky in (non-Bourne) scripts.

echo $PATH | tr \: \\n
2009-09-09 02:10:04
User: crk
Functions: echo tr
Tags: bash echo tr PATH
13

This version uses Pipes, but is easier for the common user to grasp... instead of using sed or some other more complicated method, it uses the tr command

nautilus `pwd`
zip -r foo.zip DIR -x "*/.svn/*"
find . -not \( -name .svn -prune \) -type f | xargs zip XXXXX.zip
diff <(openssl x509 -noout -modulus -in server.crt ) <( openssl rsa -noout -modulus -in server.key )
2009-09-08 12:08:34
User: ari
Functions: diff
3

A x509 certificate and a rsa key file have in common a parameter called modulus, it is a very long hexadecimal number.

That value is unique for each certficate / key pair.

The command allows to do the check of this pair of values in a script using a great feature of bash. "