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

2012-05-20 - test
test
2012-05-20 - test
test
2012-05-20 - test
test
2012-05-20 - Test tweets
YU not working?
Hide

Tags

Hide

Functions

Commands using watch

Commands using watch from sorted by
Terminal - Commands using watch - 96 results
watch 'curl -s --location -I http://any.site.or.url | grep -e "\(HTTP\|Location\)"'
2012-04-23 17:05:29
User: theist
Functions: grep watch
3

Watches the headers of a curl, following any redirects and printing only the HTTP status and the location of the possible redirects.

watch -n 5 "upower -d | grep energy -A 4"
2012-04-02 22:33:37
User: aidanlinz
Functions: watch
0

Convenient to leave running in a yakuake or plasmacon terminal.

For older kernels

watch -n 5 cat /proc/acpi/battery/BAT0/state
watch -n 2 command
2012-03-20 19:55:52
User: pranavkn
Functions: watch
0

Repeat command after every 2 secs

watch() { while true; do echo "<Ctrl+V><Ctrl+L>Every 2.0s: $@"; date; eval "$@"; sleep 2; done }
2012-03-07 09:30:15
User: hfs
Functions: echo eval sleep watch
Tags: watch
0

Usage:

watch ls -l

Basic but usable replacement for the "watch" command for those systems which don't have it (e.g. the Solaris I'm trapped on).

Type Ctrl+V to escape the following Ctrl+L which clears the screen. It will be displayed as "^L".

watch() { if [ -z "$1" ]; then echo "usage: watch interval command" return fi sec=$1 shift while test :; do clear; date=$(date); echo -e "Every "$sec"s: $@ \t\t\t\t $date"; echo $@; sleep $sec; done }
watch -n 1 "echo | sudo iptables -nvL | head -1 | awk '{print \$7}'"
watch -n 1 'ps -aux | sort -nrk 4 | head'
watch -tn1 'figlet -f slant `date +%T` | cowsay -n -f telebears'
2011-11-25 14:35:01
Functions: watch
Tags: Linux
0

You need to have figlet(for font) and cowsay installed.

Just copy n paste this command and you can see.....

watch -tn1 'date +%T | xargs banner'
2011-11-20 04:46:02
User: kev
Functions: watch xargs
Tags: banner
5

# ### ### # # ### ### # # #

## # # ### # # # # ### ## # #

# # # # ### # # # # ### # # # #

# ### ##### # # #####

# # # ### # # ### # #

# # # ### # # ### # #

##### ### ### # ##### ### ##### #

watch -n1 "ls -p | grep '/$'"
watch -n 1 "netstat -ntu | sed '1,2d' | awk '{ print \$6 }' | sort | uniq -c | sort -k 2"
watch -n1 'netstat -tn | grep -P :22'
watch -d -n 5 df
2011-08-24 19:45:36
User: pcphillips
Functions: watch
1

If you add the -d flag each difference in the command's output will be highlighted.

I also monitor individual drives by adding them to df. Makes for a nice thin status line that I can shove to the bottom of the monitor.

watch -n 2 -d '/sbin/ifconfig eth0'
watch -n 1 "/usr/sbin/lsof -p PID |awk '/TCP/{split(\$8,A,\":\"); split(A[2],B,\">\") ; split(B[1],C,\"-\"); print A[1],C[1],B[2], \$9}' | sort | uniq -c"
2011-08-12 19:16:38
User: ideivid
Functions: watch
2

Maybe this will help you to monitor your load balancers or reverse proxies if you happen to use them. This is useful to discover TIME OUTS and this will let you know if one or more of your application servers is not connected by checking.

watch !!
watch vmstat -sSM
watch -n 2 netstat -antu
watch 'netstat -anptu |egrep "^Proto|:80 "'
2011-05-18 15:05:52
User: Mozai
Functions: egrep watch
5

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".

watch "cat `ls -rcA1 | tail -n1`"
2011-03-25 01:22:05
User: donnoman
Functions: watch
1

Great for watching things like Maildir's or any other queue directory.

> /tmp/psup.log; watch "ps up $(pgrep -d, -x nginx) | grep -v STAT | awk '{print $8}' | grep -c [ZUTD] >> /tmp/psup.log; tail -n 22 /tmp/psup.log"
2011-03-16 17:49:23
User: donnoman
Functions: watch
Tags: nginx
-2

This command counts the number of blocked NGINX processes every 2 seconds and shows the last 22 measurements

You should have at least the number of cpu's in a non-blocked state.

The command up to the first ; truncates the log file.

watch -n 1 :
2011-02-16 13:38:37
User: daniele
Functions: watch
0

Clock will appear in the top-right corner

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 -n1 'date "+%T"'
2011-02-16 00:33:51
User: DaveQB
Functions: watch
4

A console clock with the current time.