2018-11-14 17:56:45 +00:00
|
|
|
---
|
|
|
|
layout: page
|
|
|
|
category-page: intermediate
|
|
|
|
category-title: Intermediate commands
|
2018-11-14 21:15:38 +00:00
|
|
|
tags: watch repeat track analyse seconds
|
2018-11-14 17:56:45 +00:00
|
|
|
author: Claudio Maggioni
|
|
|
|
title: watch
|
|
|
|
---
|
2018-11-14 21:15:38 +00:00
|
|
|
The <code>watch</code> command is a system utility able to execute a command
|
|
|
|
every <i>n</i> seconds by clearing the screen and displaying the
|
|
|
|
output of the command each time the interval is over. This command is very
|
|
|
|
simple to use and very effective: it can be used to check the size in bytes
|
|
|
|
of a file while downloading it, or it can be used on <i>Linux</i> to jiggle
|
|
|
|
around the mouse every ~5 minutes with the command <code>xdotool</code> in
|
|
|
|
order to keep the computer awake.
|
2018-11-14 17:56:45 +00:00
|
|
|
|
|
|
|
<h3>Usage</h3>
|
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
<code>watch</code> has a very simple syntax: the amount in seconds to wait
|
|
|
|
between executions is specified in seconds using the <code>-n</code> flag
|
|
|
|
and the default value is <i>2</i>. Also, differences between older and
|
|
|
|
newer outputs are highlighted if the <code>-d</code> flag is used.
|
2018-11-14 17:56:45 +00:00
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
Example: Watch the size of "ubuntu.iso" every 5 seconds
|
2018-11-14 17:56:45 +00:00
|
|
|
|
|
|
|
<pre>
|
2018-11-14 21:15:38 +00:00
|
|
|
watch -n 5 du -h ubuntu.iso
|
2018-11-14 17:56:45 +00:00
|
|
|
</pre>
|
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
Example: Watch the contents of "site.html" every 2 seconds and highlight the
|
|
|
|
differencies between iterations
|
2018-11-14 17:56:45 +00:00
|
|
|
|
|
|
|
<pre>
|
|
|
|
watch -d cat site.html
|
|
|
|
</pre>
|