fbpx watch Command in Linux: Executing Commands Periodically | Certificação Linux

watch Command in Linux: Executing Commands Periodically

📅 12/08/2021 ⏱ 2 min ✍️ Uira Ribeiro
Linuxcommands
watch Command in Linux: Executing Commands Periodically
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

Imagine you want to monitor a situation by running a command periodically.

You can use bash history and manually run the program as many times as needed, or use the watch command in Linux.

The watch command in Linux executes a command periodically, allowing you to observe how the program's output changes over time.

If no interval is specified, watch uses 2 seconds by default.

The most common options are:

  • -d        Shows the differences between updates;
  • -n X    Sets the interval to X seconds;
  • -t        Disables the header;
  • -g       Exits when the command output changes;

In this example watch can be used to monitor TCP connections:

$ watch -n 1 ss -tEvery 1,0s: ss -t          Sun Sep 15 21:37:32 2019State   Local Address:Port         Peer Address:PortESTA        127.0.0.1:http            127.0.0.1:39608ESTAB       127.0.0.1:39608           127.0.0.1:http

Learn much more about Linux in our online course. You can enroll here. If you already have an account, or want to create one, just log in or create your user here.

Liked it? Share

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp