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.

World cup college
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

2010-03-03 - Commandlinefu @ SXSW 2010
Am going to be at SXSW this year, in case you want to submit any CLI nuggets or suggestions to me in person. Ping me on the @codeinthehole Twitter account.
2009-09-12 - Email updates now available
You can now enable email updates to let you know each time you're command is commented on.
2009-07-11 - API and javascript blog widget now available
A simple API has been released, allowing commands to be retrieved in various formats. This also allows commands to be embedded on blogs/homepages.
2009-05-17 - Added duplicate suggestions to the new command form
When adding a new command, a quick background search is performed to make sure you're not duplicating a command already in the system.
Hide

Tags

Hide

Functions

All commands

All commands from sorted by
Terminal - All commands - 4,504 results
arecord -f dat | ssh -C user@host aplay -f dat
yum install vixie-cron crontabs
yum -y install bind bind-chroot caching-nameserver
yum install kernel-PAE
echo 0 >/selinux/enforce
2010-02-17 16:33:26
User: svnlabs
Functions: echo
-6

just change SELINUX=enforcing to SELINUX=permissive, and you're done. Reboot if you want to prove it.

openssl s_client -connect www.example.com:443 -prexit
2010-02-17 15:46:37
User: JonInVA
1

The key is to use the -prexit option at the command line, and then type "quit" instead of CTRL-C to exit OpenSSL. OpenSSL will then dump its last negotiated state, printing out the contents of the renegotiated handshake. Crucial for debugging client certificate configurations on web servers such as IIS, which renegotiate the SSL/TLS connection with the HTTP request in-flight to ask the client for a cert.

file /usr/bin/* | grep ELF | cut -d":" -f1
2010-02-17 14:01:52
Functions: cut file grep
-1

This is a dirty raw way to simply list ELF objects in a folder.

The output is ready to be parsed i.e to the stripper or what else needs a path to an ELF object.

DISPLAY=":0.0" import -window root screenshot.png
2010-02-17 13:02:24
User: walterl
8

The `export` is unnecessary if it's only applicable to the one command.

export DISPLAY=":0.0" && import -window root screenshot.png
2010-02-17 12:13:49
User: fraktil
Functions: export
-3

Like the given command, but combines _DISPLAY=":0.0"_ with _export DISPLAY_ to get _export DISPLAY=":0.0"_ and only imports if DISPLAY is set successfully.

find . -type f |sed "s#.*/##g" |sort |uniq -c -d
2010-02-17 11:59:54
User: shadycraig
Functions: find sed sort uniq
0

Useful for C projects where header file names must be unique (e.g. when using autoconf/automake), or when diagnosing if the wrong header file is being used (due to dupe file names)

diff -x "*CVS*" -r <path-1> <path-2> [<path-3>]
2010-02-17 11:08:17
User: braklet
Functions: diff
0

This will cause diff to ignore any files whose path matches "*CVS*", ie any CVS control files.

man intro
2010-02-17 10:11:56
User: peppet
Functions: man
4

Tested on debian and ubuntu. Translations could be useless, so "LANG=C man intro" is a better alternative.

xhost +local:
DISPLAY=":0.0"; export DISPLAY; import -window root gotya.png
2010-02-17 09:13:54
User: Abiden
Functions: export
2

Say if you're logged into a remote system via ssh and this system has an x window system, but yet you still want a screen shot of what's going on graphically. This will do it for you. :-)

spellcheck(){ typeset y=$@;curl -sd "<spellrequest><text>$y</text></spellrequest>" https://google.com/tbproxy/spell|sed -n '/s="[0-9]"/{s/<[^>]*>/ /g;s/\t/ /g;s/ *\(.*\)/Suggestions: \1\n/g;p}'|tee >(grep -Eq '.*'||echo -e "OK");}
2010-02-17 08:20:48
User: eightmillion
Functions: echo grep sed tee
5

I took matthewbauer's cool one-liner and rewrote it as a shell function that returns all the suggestions or outputs "OK" if it doesn't find anything wrong. It should work on ksh, zsh, and bash. Users that don't have tee can leave that part off like this:

spellcheck(){ typeset y=$@;curl -sd "<spellrequest><text>$y</text></spellrequest>" https://google.com/tbproxy/spell|sed -n '/s="[1-9]"/{s/<[^>]*>/ /g;s/\t/ /g;s/ *\(.*\)/Suggestions: \1\n/g;p}';}
search='spelll'; curl -sd "<spellrequest><text>$search</text></spellrequest>" https://google.com/tbproxy/spell | sed 's/.*<spellresult [^>]*>\(.*\)<\/spellresult>/\1/;s/<c \([^>]*\)>\([^<]*\)<\/c>/\1;\2\n/g' | grep 's="1"' | sed 's/^.*;\([^\t]*\).*$/\1/'
ls *.jpg | grep -n "" | sed 's,.*,0000&,' | sed 's,0*\(...\):\(.*\).jpg,mv "\2.jpg" "image-\1.jpg",' | sh
curl -s http://www.commandlinefu.com/commands/by/$1/xml | awk -F'</?div[^>]*>' '/class=\"command\"/{gsub(/&quot;/,"\"",$2); gsub(/&lt;/,"<",$2); gsub(/&gt;/,">",$2); gsub(/&amp;/,"\\&",$2); cmd=$2} /class=\"num-votes\"/{printf("%3i %s\n", $2, cmd)}'
2010-02-16 17:24:45
User: putnamhill
Functions: awk
0

This version prints current votes and commands for a user. Pass the user as an argument. While this technically "fits" as a one liner, it really is easier to look at as a shell script with extra whitespace. :)

alias info='info --vi-keys'
2010-02-16 16:35:17
User: eightmillion
Functions: alias
Tags: alias info
0

I use this alias in my bashrc. The --vi-keys option makes info use vi-like and less-like key bindings.

myinfo() { info --subnodes -o - $1 | less; }
2010-02-16 13:09:32
User: bartonski
Functions: info
6

For those who hate navigating info pages, a shell function which will dump the contents to stdout, then page it through less, thus acting like 'man'.

rsync -azE -e "ssh -pPortnumber" src_dir user@hostB:dest_dir
2010-02-16 06:30:54
User: kkk
Functions: rsync
0

From opposite host To copy remote to local

rsync -aE -e "ssh -pPortnumber" user@hostA:directory target_dir

curl -s -u $username:$password http://192.168.1.1/DHCPTable.htm | grep '<td>.* </td>' | sed 's|\t<td>\(.*\) </td>\r|\1|' | tr '\n' ';' | sed 's/\([^;]*\);\([^;]*\);/\2\t\1\n/g'
2010-02-16 02:27:11
User: matthewbauer
Functions: grep sed tr
-2

Will create a sample etc host file based on your router's dhcp list.

Now I know this won't work on most routers, so please don't downvote it just because it doesn't work for you.

tc qdisc add dev <dev> root handle 1: cbq avpkt 1000 bandwidth 100mbit;tc class add dev <dev> parent 1: classid 1:1 cbq rate 300kbit allot 1500 prio 5 bounded isolated;tc filter add dev <dev> parent 1: protocol ip prio 16 u32 match ip dst <ip> flowid 1:1
2010-02-16 01:39:09
User: din7
0

Tc is used to configure Traffic Control in the Linux kernel. See man tc for further details.

This series of commands will limit the bandwidth of the specified device to the limit you set (300kbit in the second command) to the address you specify.

username=bartonski;curl -s http://www.commandlinefu.com/commands/by/$username/json|perl -e 'BEGIN{$s=0;$n=0};END{print "Score: $s\nEntries: $n\nMean: ";printf "%3.2f\n",$s/$n}' -0173 -nae 'foreach $f (@F){if($f =~ /"votes":"(-*\d+)"/){$s += $1; $n++;}}'
2010-02-16 01:03:29
User: bartonski
Functions: perl
1

Like command #4845, prints score, number of entries, and average score.

type <command>