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,927 results
swapoff -a ; swapon -a
2009-03-25 03:30:41
User: alperyilmaz
Functions: swapoff swapon
Tags: swapoff swapon
10

When you run a memory intensive application (VirtualBox, large java application, etc) swap area is used as soon as memory becomes insufficient. After you close the program, the data in swap is not put back on memory and that decreases the responsiveness. Swapoff disables the swap area and forces system to put swap data be placed in memory. Since running without a swap area might be detrimental, swapon should be used to activate swap again.

Both swapoff and swapon require root privileges.

watch -n 7 -d 'uptime | sed s/.*users,//'
2009-03-25 02:52:36
User: detert
Functions: sed watch
2

helps you keep watch on the load of a system, without having to stare constantly at the terminal. The -d argument to watch highlights the difference from the last run, making it easier to note how the load is fluctuating. The sed command just strips off the information about how long the box has been up, and how many users are logged in.

mount -t smbfs //$server/share /local/mount -o rw,username=$USER
2009-03-25 01:05:17
User: sufoo
Functions: mount
1

Mount an smb share with this command. other options -ousername=$USERr,gid=$groupname,scope=rw

awk '{sum+=$1; sumsq+=$1*$1} END {print sqrt(sumsq/NR - (sum/NR)**2)}' file.dat
seq 0 0.1 20 | awk '{print $1, cos(0.5*$1)*sin(5*$1)}' | graph -T X
2009-03-24 21:46:59
User: kaan
Functions: awk seq
2

The arguments of "seq" indicate the starting value, step size, and the end value of the x-range. "awk" outputs (x, f(x)) pairs and pipes them to "graph", which is part of the "plotutils" package.

seq 6 | awk '{for(x=1; x<=5; x++) {printf ("%f ", rand())}; printf ("\n")}'
2009-03-24 21:33:38
User: kaan
Functions: awk printf seq
Tags: awk seq
3

Displays six rows and five columns of random numbers between 0 and 1. If you need only one column, you can dispense with the "for" loop.

awk '{sum1+=$1; sum2+=$2} END {print sum1/NR, sum2/NR}' file.dat
2009-03-24 21:22:14
User: kaan
Functions: awk
Tags: awk
2

This example calculates the averages of column one and column two of "file.dat". It can be easily modified if other columns are to be averaged.

mplayer -vo null -vc null -ao pcm:fast:file=file.wav file.mp3; faac -b 128 -c 44100 -w file.wav
2009-03-24 21:04:35
User: llama
1

I use this to convert mp3 files to m4a files that can be used as ringtones on the iPhone. I've documented the process here: http://www.control-d.com/?p=60

find -depth . | (while read FULLPATH; do BASENAME=`basename "${FULLPATH}"`; DIRNAME=`dirname "${FULLPATH}"`; mv "${DIRNAME}/${BASENAME}" "${DIRNAME}/${BASENAME// /_}"; done)
2009-03-24 21:04:32
User: mohan43u
Functions: find mv read
-9

Takes filenames and directory names and replace space to '_'.

rpm -qa --qf '%{name}-%{version}-%{release}.%{arch}\n'
2009-03-24 20:42:17
User: llama
Functions: rpm
Tags: rpm
0

The queryformat option can be used in a number of ways to find things like duplicate packages, wrong arch, or the exact package to pass to rpm -e, yum remove, etc.

seq 50| awk 'BEGIN {a=1; b=1} {print a; c=a+b; a=b; b=c}'
2009-03-24 20:39:24
User: kaan
Functions: awk seq
Tags: awk seq
13

Another combination of seq and awk. Not very efficient, but sufficiently quick.

snmpwalk -v3 -On -u <user> -l AuthPriv -a SHA -A <auth_password> -X <encryption_password> -m ALL <HOST_IP> .
snmpwalk -v3 -On -u <user> -l AuthNoPriv -a SHA -A <auth_password> -m ALL <HOST_IP> .
snmpwalk -v3 -On -u <user> -l AuthNoPriv -a MD5 -A <auth_password> -m ALL <HOST_IP> .
snmpwalk -v3 -On -u <user> -l NoAuthNoPriv -m ALL <HOST_IP> .
snmpwalk -v2c -c <community> -m ALL <HOST_IP> .
seq 100 | awk '{sum+=$1} END {print sum}'
2009-03-24 20:30:40
User: kaan
Functions: awk seq
Tags: awk seq
4

"seq 100" outputs 1,2,..,100, separated by newlines. awk adds them up and displays the sum.

"seq 1 2 11" outputs 1,3,..,11.

Variations:

1+3+...+(2n-1) = n^2

seq 1 2 19 | awk '{sum+=$1} END {print sum}' # displays 100

1/2 + 1/4 + ... = 1

seq 10 | awk '{sum+=1/(2**$1)} END {print sum}' # displays 0.999023
alias tproxy='ssh -ND 8118 user@server&; export LD_PRELOAD="/usr/lib/libtsocks.so"'
alias myip='curl -s www.wieistmeineip.de | egrep -o "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"'
sed 's/\b\(0*\)//g' filename
2009-03-24 20:19:42
User: alperyilmaz
Functions: sed
Tags: sed
1

Leading zeros might help correct sorting and they can be removed by sed after sorting

sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta' filename
2009-03-24 20:06:02
User: alperyilmaz
Functions: sed
Tags: sed
3

Does not necessarily require a file to process, it can be used in a pipe as well:

cat filename | sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta'

I don't remember where I copy/pasted this from, I wish I credited the original author

head -c $((<pw-lenght>-2)) /dev/urandom | uuencode -m - | sed -e '1d' -e '3d' | sed -e 's/=.*$//g'
2009-03-24 20:05:16
User: P17
Functions: head sed uuencode
-2

Replace < pw-length > with the desired password-length.

The password-length is not always correct, but wayne...

watch ethtool eth0
2009-03-24 20:03:25
User: israel
Functions: watch
0

verifry if link detected or no and speed of network.

mysql DATABASE -N -s -r -e 'SQL COMMAND'
2009-03-24 19:53:46
User: alperyilmaz
Tags: mysql
5

-N removes header

-s removes separator chars

-r raw output

After using these options, the MySQL ouptut can be used with pipes very easily

ps ax | grep <processname> | grep -v grep | awk '{print $1}' | sudo xargs kill -9