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.

Universal configuration monitoring and system of record for IT.
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

May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!
Hide

Top Tags

Hide

Functions

Hide

Credits

All commands from sorted by
Terminal - All commands - 12,176 results
awk 'NR==linenumber' filename
echo 213.251.145.96 wikileaks.com | sudo tee -a /etc/hosts
2010-12-13 03:31:07
User: matthewbauer
Functions: echo sudo tee
-4

This one is a little bit easier for those of us that aren't always root.

fdisk -l
snmpwalk -v3 -On -u <user> -l NoAuthNoPriv -m ALL <HOST_IP> .
while true; do netstat -p |grep "tcp"|grep --color=always "/[a-z]*";sleep 1;done
2009-07-16 04:52:49
User: buffer
Functions: grep netstat
-4

The -p parameter tell the netstat to display the PID and name of the program to which each socket belongs or in digestible terms list the program using the net.Hope you know what pipe symbol means!

Presently we wish to only moniter tcp connections so we ask grep to scan for string tcp, now from the op of grep tcp we further scan for regular expression /[a-z]*.

Wonder what that means ?

If we look at the op of netstat -p we can see that the name of the application is preceded by a / ( try netstat -p ) so,now i assume application name contains only characters a to z (usually this is the case) hope now it makes some sense.Regular expression /[a-z]* means to scan a string that start with a / and contains zero or more characters from the range a-z !!. Foof .. is t

snmpwalk -v3 -On -u <user> -l AuthNoPriv -a MD5 -A <auth_password> -m ALL <HOST_IP> .
cat *
2011-12-08 05:32:14
User: bahamas10
Functions: cat
-4

no need for a for loop when cat takes multiple arguments

snmpwalk -v3 -On -u <user> -l AuthNoPriv -a SHA -A <auth_password> -m ALL <HOST_IP> .
links2 -dump http://checkip.dyndns.com | cut -d ' ' -f7
ssh -t myserver.org 'sudo ls /etc'
2013-04-09 04:23:37
User: patko
Functions: ls ssh
Tags: ssh sudo
-4

This command will ask for remote sudo password before executing a remote command.

snmpwalk -v3 -On -u <user> -l AuthPriv -a SHA -A <auth_password> -X <encryption_password> -m ALL <HOST_IP> .
geoip() { lynx -dump "http://www.geoiptool.com/en/?IP=$1" | sed -n '/Host Name/,/Postal code/p' ; }
2011-02-04 14:12:02
User: vando
Functions: sed
-4

Shows you the geolocation of an IP address.

lynx -dump -nolist http://whatthecommit.com/|sed -n 2p
2011-04-17 17:45:18
User: houghi
Functions: sed
-4

Fetch comical VC commit messages from whatthecommit.com

find -name ".svn" -exec rm -rf {} \;
wget -r -k -l 7 -p -E -nc http://site.com/
2011-08-20 10:16:06
User: realjkeee
Functions: wget
-4

-r ? указывает на то, что нужно рекурсивно переходить по ссылкам на сайте, чтобы скачивать страницы.

-k ? используется для того, чтобы wget преобразовал все ссылки в скаченных файлах таким образом, чтобы по ним можно было переходить на локальном компьютере (в автономном режиме).

-p ? указывает на то, что нужно загрузить все файлы, которые требуются для отображения страниц (изображения, css и т.д.).

-l ? определяет максимальную глубину вложенности страниц, которые wget должен скачать (по умолчанию значение равно 5, в примере мы установили 7). В большинстве случаев сайты имеют страницы с большой степенью вложенности и wget может просто ?закопаться?, скачивая новые страницы. Чтобы этого не произошло можно использовать параметр -l.

-E ? добавлять к загруженным файлам расширение .html.

-nc ? при использовании данного параметра существующие файлы не будут перезаписаны. Это удобно, когда нужно продолжить загрузку сайта, прерванную в предыдущий раз.

wget -q -O - "$@" <url>
echo -e "GET /automation/n09230945.asp HTTP/1.0\r\nHost: whatismyip.com\r\n" | nc whatismyip.com 80 | tail -n1
sudo lsof|sed 's/ */ /g'|cut -f3 -d' '|sort -u
2010-07-07 08:20:28
User: binaryten
Functions: cut sed sort sudo
-4

Most systems (at least my macbook) have system users defined, such as _www and using "users" for example will not list them. This command allows you to see who the 'virtual' users are on your system.

function mkdcd () { mkdir "$1" && cd "$1" }
python3
findfile() { find . -type f -iname "*${*}*" ; }
2015-01-01 03:15:51
User: Xk2c
Functions: find
Tags: find function
-4

Actually your func will find both files and directorys that contain ${1}.

This one only find files.

..and to look only for dirs:

finddir() { find . -type d -iname "*${*}*" ; }

svn log | grep "bodge\|fudge\|hack\|dirty"
2009-05-15 09:55:44
User: root
Functions: grep
-4

A good way to understand what you've let yourself in for. Potential project metric could be the count:

svn log | grep -c "bodge\|fudge\|hack\|dirty"
accurev stat -M -fl | awk '{print "\"" $0 "\""}' | xargs accurev pop
[ ~/temp/foo/bar/baz ] $ .. 3
2015-01-01 20:41:17
User: Xk2c
-4

many have aliases like:

alias ...="cd ../../"

alias ....="cd ../../../"

and so furth.

..() mitigates to need for those aliases, see sample output for an example

# .. -> go up 1 directory

# .. 4 -> go up 4 directories

..()

{

local DIR=''

declare -i NUM=0

if [[ ${1} =~ ^[1-9][0-9]*$ ]]

then

while (( ${NUM} < ${1:-1} ))

do

DIR="${DIR}../"

NUM=$(( ${NUM} + 1 ))

done

else

DIR=..

fi

cd "${DIR}"

}

grep query -r . --exclude-dir=.svn