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 tagged watch from sorted by
Terminal - Commands tagged watch - 42 results
watch 'netstat -anptu |egrep "^Proto|:80 "'
2011-05-18 15:05:52
User: Mozai
Functions: egrep watch
7

Shows updated status in a terminal window for connections to port '80' in a human-friendly form. Use 'watch -n1' to update every second, and 'watch -d' to highlight changes between updates.

If you wish for status updates on a port other than '80', always remember to put a space afterwards so that ":80" will not match ":8080".

while cat /proc/net/dev; do sleep 1; done | awk '/eth0/ {o1=n1; o2=n2; n1=$2; n2=$10; printf "in: %9.2f\t\tout: %9.2f\r", (n1-o1)/1024, (n2-o2)/1024}'
while :; do OLD=$NEW; NEW=`cat /proc/net/dev | grep eth0 | tr -s ' ' | cut -d' ' -f "3 11"`; echo $NEW $OLD | awk '{printf("\rin: % 9.2g\t\tout: % 9.2g", ($1-$3)/1024, ($2-$4)/1024)}'; sleep 1; done
while [ /bin/true ]; do OLD=$NEW; NEW=`cat /proc/net/dev | grep eth0 | tr -s ' ' | cut -d' ' -f "3 11"`; echo $NEW $OLD | awk '{printf("\rin: % 9.2g\t\tout: % 9.2g", ($1-$3)/1024, ($2-$4)/1024)}'; sleep 1; done
2011-03-22 10:02:23
User: hons
Functions: awk cut echo grep sleep tr
15

Just a simple way without the need of additional tools. Of course, replace eth0 with your IF.

watch -t -n1 'date "+%r %F %A"'
2011-02-16 03:05:48
User: oracular
Functions: watch
Tags: date clock watch
5

Shows a simple clock in the console

-t param removes the watch header

Ctrl-c to exit

watch -n 900 "notify-send -t 10000 'Look away. Rest your eyes'"
2010-10-05 09:39:31
User: b_t
Functions: watch
0

Note:

1) -n option of watch accepts seconds

2) -t option of notify-send accepts milliseconds

3) All quotes stated in the given example are required if notification

message is more than a word.

4) I couldn't get this to run in background (use of & at the end fails). Any

suggestions/improvements welcome.

watch 'ls -tough --full-time *.vmdk'
2010-08-20 17:28:28
User: vRobM
Functions: watch
1

To monitor .vmdk files during snapshot deletion (commit) on ESX only (ESXi doesn't have the watch command):

1. Navigate to the VM directory containing .vmdk files.

# watch "ls -tough --full-time *.vmdk"

where:

-t sorts by modification time

-o do not list group information (to narrow the output)

-u sorts by access time

-g only here for the purpose to easily remember the created mnemonic word 'tough'

-h prints sizes in human readable format (e.g., 1K 234M 2G)

--full-time sets the time style to full-iso and does not list user information (to narrow the output)

optionally useful parameters to the watch command:

-d highlight changes between updates

-n seconds to wait between updates (default is 2)

-t turn off printing the header

watch 'find -maxdepth 1 -mindepth 1 -type d |xargs du -csh'
2010-05-19 13:13:57
User: shadycraig
Functions: du watch xargs
0

This command shows the size of directories below here, refreshing every 2s.

It will also track directories created after running the command (that what the find bit does).

watch -n 1 "sudo asterisk -vvvvvrx 'core show channels' | grep call"
2010-03-26 15:42:13
User: mheadd
Functions: watch
6

Show active calls as the happen on an Asterisk server. Note that the Asterisk command (in single quotes) is formatted for Asterisk 1.6. Use the -n flag on the watch command to modify the refresh period (in seconds - default is 2 seconds).

watch -n1 snmptable -v2c -c public localhost diskIOTable
2010-03-19 11:31:52
User: oernii2
Functions: watch
4

Show a simple table with disk IO for the specified host. you monitor a LOT of different thing. Mostly used for MRTG and similar, but this is nice for a quick look, which disk is busy.

"public" is your SNMP community

ensure that snmpd is running on the host which you intend to monitor

watch -d 'ls -l'
2009-09-03 20:12:36
User: 0disse0
Functions: watch
Tags: watch stats
0

To highlight the difference between screen updates

watch 'cat /proc/loadavg'
2009-09-03 20:10:46
User: 0disse0
Functions: watch
Tags: status watch
1

If you need to keep an eye on a command whose output is changing, use the watch command. For example, to keep an eye on your load average

watch --interval 0 'iptables -nvL | grep -v "0 0"'
2009-08-22 18:18:05
User: Code_Bleu
Functions: grep watch
6

This will allow you to watch as matches occur in real-time. To filter out only ACCEPT, DROP, LOG..etc, then run the following command: watch 'iptables -nvL | grep -v "0 0" && grep "ACCEPT"' The -v is used to do an inverted filter. ie. NOT "0 0"

watch "ps auxw | grep [d]efunct"
2009-08-12 08:11:16
User: alvinx
Functions: watch
6

to omit "grep -v", put some brackets around a single character

watch "ps auxw | grep 'defunct' | grep -v 'grep' | grep -v 'watch'"
2009-08-11 12:22:13
Functions: watch
5

Shows all those processes; useful when building some massively forking script that could lead to zombies when you don't have your waitpid()'s done just right.

ls -drt /var/log/* | tail -n5 | xargs sudo tail -n0 -f
2009-07-22 14:44:41
User: kanaka
Functions: ls sudo tail xargs
Tags: bash tail log watch
5

This command finds the 5 (-n5) most frequently updated logs in /var/log, and then does a multifile tail follow of those log files.

Alternately, you can do this to follow a specific list of log files:

sudo tail -n0 -f /var/log/{messages,secure,cron,cups/error_log}

watch -t -n1 "date +%T|figlet"
2009-06-21 01:02:37
User: dennisw
Functions: watch
43

This command displays a clock on your terminal which updates the time every second. Press Ctrl-C to exit.

A couple of variants:

A little bit bigger text:

watch -t -n1 "date +%T|figlet -f big"

You can try other figlet fonts, too.

Big sideways characters:

watch -n 1 -t '/usr/games/banner -w 30 $(date +%M:%S)'

This requires a particular version of banner and a 40-line terminal or you can adjust the width ("30" here).