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 using watch from sorted by
Terminal - Commands using watch - 127 results
watch "asterisk -vvvvvrx 'core show channels' | egrep \"(call|channel)\""
2012-08-29 13:40:45
User: rowshi
Functions: watch
1

This handles when you have a single call or channel. Other commands will strip out the result if there is a single channel or call active because the output changes the noun to be singular instead of plural.

watch -n10 "if test -e run.txt ; then chmod +x script.sh && ./script.sh && rm run.txt || rm run.txt && echo > failed.txt ; fi"
2012-07-29 00:38:08
User: bugmenot
Functions: watch
0

You can upload via ftp the script.sh in unix text format, and then upload a file called run.txt to execute once the script. Such script can be multiline. If the script fails a failed.txt will be generated that you can see via ftp.

watch 'mysql -e "show full processlist;"'
watch -n 1 "do foo"
2012-07-11 13:42:26
User: mesuutt
Functions: watch
11

Short method of "while x=0; do foo ; sleep 1 ; done"

watch -n 1 "awk 'NR==3 {print \"Signal strength = \" \$3 \"00 %\"}''' /proc/net/wireless"
watch -n 1 cat /proc/net/wireless
2012-06-07 10:38:21
User: cantormath
Functions: cat watch
-3

Values will depend on the driver and the hardware specifics, so you need to refer to your driver documentation for proper interpretation of those values.

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.

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
2

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