FreeBSD watch command is not GNU/Linux watch command

Having done Linux administration for over 10 years now, I use the watch command almost every day. On Linux, watch will run a command every couple seconds. It’s particularly nice for watching files change:

watch ls -lah

This example will keep showing the output of ls -lah every 2 seconds.

About a year ago I switched a couple servers over to FreeBSD 6.1 because of its security features and more stable development model. For the last year I’ve been occasionally using the watch command on FreeBSD and getting an annoying error like this:

[steve@devel /backup]$ watch ls -lah
watch: fatal: bad device name

Today it finally occurred to me to look at the manpage:

WATCH(8)                FreeBSD System Manager's Manual               WATCH(8)

watch -- snoop on another tty line

watch  -cinotW -f snpdev tty

The watch utility allows the user to examine all data coming through a
specified tty using the snp(4) device.  If the snp(4) device is not
available, watch will attempt to load the module (snp).  The watch utility writes to standard output.

It hardly looks like the watch I know! It turns out that FreeBSD has a different use for watch - snooping on other consoles. On FreeBSD, the GNU watch (like on Linux) is called gnu-watch. If you don’t want to install it, you can easily whip up a poor-man’s replacement:

while [ 1 -lt 2 ]; do
  echo ------------------------------------
  eval $@
  sleep 2

TIP: To replace the default ‘watch’ with this script, save the above script as /root/watch, then make it executable, chmod +x /root/watch and alias it in your shell, alias watch='/root/watch'. You can save this alias permanently with the bash shell by adding it to ~/.bash_profile.

Here’s a sample output from the poor-man’s watch:

Thu Jul 10 22:09:27 EDT 2008
total 17113832
drwxr-xr-x   3 root  wheel   512B Jul 10 21:03 .
drwxr-xr-x  21 root  wheel   512B Jul 10 18:25 ..
-rw-r--r--   1 root  wheel    97M Jul 10 15:41 archive1.tar
-rw-r--r--   1 root  wheel    40M Jul 10 15:41 archive1.tar.bz2
-rw-r--r--   1 root  wheel   308M Jul 10 17:19 archive2.tar
-rw-r--r--   1 root  wheel    93M Jul 10 17:19 archive2.tar.bz2
-rw-r--r--   1 root  wheel   600M Jul 10 17:13 archive2a.tar
-rw-r--r--   1 root  wheel   192M Jul 10 17:13 archive2a.tar.bz2
-rw-r--r--   1 root  wheel   3.3G Jul 10 19:09 archive2b.tar
-rw-r--r--   1 root  wheel   1.4G Jul 10 19:09 archive2b.tar.bz2
-rw-r--r--   1 root  wheel   5.4G Jul 10 19:33 archive2c.tar
-rw-------   1 root  wheel   1.9G Jul 10 22:09 archive2c.tar.bz2
-rw-r--r--   1 root  wheel   2.1G Jul 10 17:44 archive2d.tar
-rw-r--r--   1 root  wheel   886M Jul 10 16:08 archive3.tar
drwxr-xr-x   2 root  wheel   512B Jul 10 19:44 scripts


COO @scientiamobile