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 -n 1 nc localhost 80 '<<EOF GET / HTTP/1.1 Host: tux-ninja Connection: Close EOF'
2009-08-06 23:20:31
User: JustinHop
Functions: watch
1

Use the command watch, which is really hard to pass nested quotes to, and insert newlines where they are supposed to go in the HTTP request. that is after 1.1 after the host and two newlines at the end before the EOF.

i use this all day

what? no support for HEREDOCs on commandlinefu's interface? need more fu.

watch lsof -i :80
watch 'netstat -aniv'
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).

watch -d -n 3 "iw dev wlan0 station dump; iwconfig wlan0"
watch '/home/mm/bash/keypress.sh |/home/mm/bash/evento.sh'
2009-06-07 20:57:49
User: m33600
Functions: watch
-7

evento.sh needed for awk syntax

the aplay command makes a camera sound. It takes a picture of who looked at the display

#!/bin/bash

# evento.sh: deteta evento e fala

awk '{print}' | espeak -v pt -stdin

awk '/e/{print "emergencia"}' | espeak -v pt -stdin

aplay -q /home/mm/bash/camera.wav # -q inibe verbose do comand aplay

exit 0

watch "dmesg |tail -15"
2009-04-14 03:13:17
User: Buzzcp
Functions: watch
11

Other logs can be monitored similarly, e.g.

watch "tail -15 /var/log/daemon.log"
watch -n 1 "netstat -tpanl | grep ESTABLISHED"
watch -tn1 'bc<<<"`date -d'\''friday 21:00'\'' +%s`-`date +%s`"|perl -ne'\''@p=gmtime($_);printf("%dd %02d:%02d:%02d\n",@p[7,2,1,0]);'\'
2009-03-29 19:53:36
User: penpen
Functions: perl watch
Tags: Linux unix date
-2

An improved version of http://www.commandlinefu.com/commands/view/1772/simple-countdown-from-a-given-date that uses Perl to pretty-print the output. Note that the GNU-style '--no-title' option has been replaced by its one-letter counterpart '-t'.

watch --no-title -d -n 1 'echo `date -d "next Thursday" +%s` "-" `date +%s` | bc -l'
2009-03-29 06:53:09
User: jnash
Functions: bc watch
0

Might be more useful if you were able to print it in Days HH:MM:SS format as:

perl -e '@p=gmtime(234234);printf("%d Days %02d:%02d:%02ds\n",@p[7,2,1,0]);'

But I'm not exactly sure how to replace the 234234 with the output of the countdown time. (Having some problems with nested quoting/command substitution). Help would be appreciated :)

watch -n 10 "wget -q http://www.brillig.com/debt_clock -O - | grep debtiv.gif | sed -e 's/.*ALT=\"//' -e 's/\".*//' -e 's/ //g'"
2009-03-26 19:32:57
User: matrtsmiller
Functions: watch
2

The idea was originally stolen from Linux Journal. 'wget' pulls the debt clock and 'sed' reformats it for general consumption. Prefacing the command with 'watch' simply sets an interval - in this case every 10 seconds.

watch -n1 --differences cat /proc/meminfo
watch -n 1 :
2009-03-25 23:00:28
User: penpen
Functions: watch
Tags: Linux unix
-2

'watch' repeatedly (default every 2 seconds, -n 1 => every second) runs a command (here ':', a shorthand for 'true'), displays the output (here nothing) and the date and time of the last run.

I thought it to be obvious but it seemingly is not: to exit use Ctrl-C.

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.

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

verifry if link detected or no and speed of network.

watch -n 1 uptime\;myqladmin --user=<user> --password=<password> --verbose processlist
2009-03-21 18:29:28
User: root
Functions: watch
Tags: mysql
-6

Useful for monitoring both MySQL and the server load at the same time.

watch 'iptables -vL'
2009-03-20 14:49:12
User: alanr723
Functions: watch
3

Watch the number of packets/bytes coming through the firewall. Useful in setting up new iptables rules or chains. Use this output to reorder rules for efficiency.

watch -n 5 -d cat /proc/mdstat
watch -n 1 df
2009-02-18 21:34:06
User: joem86
Functions: watch
5

While copying a large file that may take up a good chunk of your hard drive, start the copy and run this command concurrently. It will print out the disk information every second. It's pretty handy when you have a large copy with nothing to monitor the progress.

watch -d "free -mt"
watch ifconfig eth0
watch -n 1 mysqladmin --user=<user> --password=<password> processlist
2009-02-16 11:21:16
User: root
Functions: watch
Tags: mysql
45

Watch is a very useful command for periodically running another command - in this using mysqladmin to display the processlist. This is useful for monitoring which queries are causing your server to clog up.

More info here: http://codeinthehole.com/archives/2-Monitoring-MySQL-processes.html

watch ccache -s
2009-02-13 17:16:32
User: piyo
Functions: watch
-1

OMG, you are a Gentoo junkie.

-funroll-loops-me-harder ;-)

http://ccache.samba.org/

ccache is a compiler cache, which speeds up your compiler on successive runs, because it caches intermediate compiled output.

watch -n 15 curl -s --connect-timeout 10 http://www.google.com/
2009-02-10 21:48:45
User: dltj
Functions: watch
6

If your web server is down, this command will periodically attempt to connect to it. If the output is blank, your server is not yet up. If you see HTML, your server is up. Obviously, you need to replace the Google URL with your web server URL...

* 'watch' -- a command for re-executing a command and displaying

the output

* '-n 15' -- tells watch to redo the command every 15 seconds

* 'curl' -- a handy utility for getting the source of a web page

* '-s' -- tells curl to be silent about failing

* '--connect-timeout 10' -- Try to connect for 10 seconds

watch "df | grep /this/folder/"