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

Commands by rockon from sorted by
Terminal - Commands by rockon - 18 results
ps -eo size,pid,user,command --sort -size |awk '{hr[1024**2]="GB";hr[1024]="MB";for (x=1024**3; x>=1024; x/=1024){if ($1>=x){printf ("%-6.2f %s ", $1/x, hr[x]);break}}}{printf ("%-6s %-10s ", $2, $3)}{for (x=4;x<=NF;x++){printf ("%s ",$x)} print ("\n")}'
watch -n1 "uptime && ps auxw|grep http|grep -v grep | grep -v watch|wc -l && netstat -ntup|grep :80 |grep ESTABLISHED|wc -l && netstat -ntup|grep :80|grep WAIT|wc -l && free -mo && ps -ylC httpd --sort:rss|tail -3|awk '{print \$8}'"
2012-06-06 12:12:10
User: rockon
Functions: watch
2

In certain cases you mighy need to monitor the server load caused by certain process. For example HTTP, while stress testing apache using ab (apache benchmark) you may want to monitor the server status,load, # of spawned HTTP processes, # of established connections, # of connections in close wait state, apache memory footprint etc.

php -m
httpd -M
2012-05-27 12:04:17
User: rockon
1

Easiest way to check which modules are loaded in apache.

sestatus -v
2012-05-27 11:48:25
User: rockon
Tags: selinux
1

Usefule to check whether SELinux is in force or disabled.

Though you need to be superuser while execute this command.

mysqladmin -u root -p extended-status
openssl s_client -connect www.example.com:443 > /tmp/example.com.cert
2012-05-04 06:15:27
User: rockon
2

Useful when we need to create new certificate for site when current one is near expiry.

This downloaded cert can be used to provide organisational data directly to new cert. using below command.

e.g. openssl x509 -x509toreq -in /tmp/example.com.cert -out example.com.csr -signkey example.com-key.pem

sar -u 2 5
2009-03-02 04:54:37
User: rockon
2

Generated the CPU utilization stats with 5 lines /every 2 seconds.

Needs sysstat package to be installed prior to use sar.

lsof +p xxxx
cp /some/path/to/myfile{,.back}
2009-03-02 04:41:18
User: rockon
Functions: cp
1

Copy the file with the given .extension at the source file's location. Eliminates the typing of long paths again and again.

ethtool -S eth0
bzgrep -i "pattern" pattern.bz2
2009-03-01 10:21:26
User: rockon
Functions: bzgrep
0

Search the pattern in bzip2 compressed file with out having to unzip.

pinky -l <username>
2009-03-01 10:17:08
User: rockon
Functions: pinky
1

Gives information about user's home directory and real name and shell user is having.

hdparm -i[I] /dev/sda
2009-03-01 10:00:28
User: rockon
Functions: hdparm
9

Get the hard disk information with out shutting down and opening the system.

It gives information on model no., serial no., cylinders/heads/sectors, and the supported features of the hard disk.

lsb-release -a
2009-03-01 09:42:52
User: rockon
1

To know the OS distro and version, release.

Is same like /etc/redhat-release

dmidecode | grep -i prod
2009-02-25 23:05:17
User: rockon
Functions: grep
6

This command gives a model information of a computer. Also useful in determining the host is a VM machine or actual physical machine.

IPADDR=`ifconfig eth0 | grep -i inet | awk -F: '{print $2}'| awk '{print $1}'`
2009-02-25 22:58:19
User: rockon
Functions: awk grep
-1

Useful in scripts while you just need an IP address in a variable.

rm -rf `ls | head -5000`
2009-02-25 22:52:23
User: rockon
Functions: head rm
-3

Deletes thousands of files at one go, I'm not able to recall the exact # of files that rm can delete at one go(apprx. around 7000.)