15 Methods To Use Linux Watch Multiple Commands

The linux watch multiple commands supplies a helpful way of executing commands occasionally. Lots of system admins utilize this easy tool to get live feedback from regularly utilized Linux terminal commands. Moreover, it likewise permits us to locate modifications in command outputs in real-time.

15 Methods To Use Linux Watch Multiple Commands

In this article, you can know about linux watch multiple commands here are the details below;

In this guide, we have gone over the various usage cases of the watch energy and highlight many helpful usages of this tool for our readers. If you were trying to find a method to run commands consistently, continue reading with us. You will discover to utilize among the most helpful yet typically ignored Linux commands.

Useful Examples of Linux Watch Command

Using the Linux watch utility is a simples and straightforward task. It follows a basic syntax, and the absence of intricate choices eliminates the need to keep in mind many staff. Have a look at the following examples to learn how the watch works and execute it in your daily activities.

1. Fundamental Usage of Linux Watch Command

When utilized with no command-line arguments, the watch energy will run the specified command every two seconds. Have a look at the following simple example to see how it works.

$ see date

If you run the above commands in your favorite Linux terminal emulator, it will print the date command’s output on your screen. The output will be refreshed every two seconds. The top part of the screen will display which commands is being run by the watch and the active interval duration.

linux watch multiple commands

2. Specify the Update Interval

Users can specify the interval duration for their watch program easily by using the -n alternative. You will need to offer the new interval time (in seconds), followed by this alternative. The following illustration shows how it works in practice.

$ watch -n five-date

This command will run likewise to the above command; however, it will just upgrade the result every 5 seconds. The top-right corner of the screen will show the current time after each refresh. You can also utilize the long-form– a period in place of the -n alternative, as revealed listed below.

$ watch– interval five-date

Use the Ctrl+ C mix to give up the watch command and return to your terminal session.

3. Highlight Differences Between Each Update

The watch energy makes it basic to spot distinctions in between the old and upgraded output. You can makes use of the -d flag to turn on distinction highlighting. The below command needs to supply a useful illustration of this choice.

$ watch -n 5 -d date

This command will run the date energy every five seconds and highlight the output’s modifications on your terminal screen. There is a long style syntax for the -d choice called– distinctions, detailed below.

$ watch -n 5– differences date

The -d -or– distinctions options also take an optional argument called ‘irreversible.’ When you define this parameter, the cursor highlighter will become permanent instead of being on and off.

$ watch -n 5– distinctions= permanent date

4. Turn of Title and Headers

You must discover by now that the Linux watch command reveals information like the command name that’s being run, the period, and the current time at the top of the screen. You can utilize the -t choice of watch to disable this info. Check out the following examples to see how it works.

$ watch -t date

As anticipated, this will only display the output produced by the date command. It likewise strips the extra blank line you’d see when not utilizing the -t option. Users can likewise choose to utilize the long-style syntax– not-title for this option, as demonstrated below.

$ watch– no-title date

linux watch multiple commands

5. Exit Watch on Error

You can define your watch command to exit whenever the command produces a mistake it is running. Simply include the -e option, and the watch will exit when the output contains a mistake. The below command highlights this using an extremely simple example.

$ watch -e exit 99

If you copy the above Linux watch of the command and run it, it will display a prompt saying that the command has a non-zero exit status. Pressing any key on your keyboard will leave the execution. Note that commands that perform without any error exit with a no status code. So, having a non-zero code indicates that the command produced a mistake.

$ watch– errexit exit 99

The– errexit choice is an alternative syntax for -e.

6. Exit Watch on Changes in Output

The -g flag of the watch energy signals an exit whenever there is a modification in the output. This can be useful for people who wish to set a simple tracking session right from their terminal window. Take a look at the listed below example to find out how this works.

$ watch -g date

This command will run for 2 seconds, and as quickly as the output updates, it will leave. This was a rather easy illustration, but you need to have the ability to master it. For instance, you could utilize this command to track network resources and get alerted when something modifications.

$ see– chgexit netstat– al

. The above example utilizes the long-form of the -g option, which is– chgexit.

7. Alert on Error.

The Linux watch energy’s -b choice rings a beep tone whenever the command exits with a non-zero status code. As gone over already, a non-zero status code usually points to a mistake or failure to carry out the offered command. This makes it simple to identify such issues.

$ watch -b date.

This command will give a beeping noise if the output of the date command includes a mistake. Although the date is unlikely to trigger any mistake, it highlights how the -b alternative can be used. You might also use the abbreviated syntax– beep in place of the -b option.

$ view– beep date.

Nevertheless, the beep program should be installed on your system. Otherwise, the watch will not have the ability to ring the sound.

8. Interpret Color Codes and Style Sequences.

You can allow the analysis of ANSI color codes and style series for the watch utility using either among the -c or– color options. By default, the watch does not analyze colors on its output. Take a look at the below example carefully to see how this alternative works.

$ watch -c echo “$( output setaf 1) Welcome to hubtech”.

The output of this command consists of the color-coded string “Welcome to hubtech.” Now, remove the -c option and run the command again. You will see that the string does not contain any colors this time around. The long-form syntax for this choice is– color.

linux watch multiple commands

9. Run Commands in Precise Intervals.

When you utilize the -n option for specifying command execution intervals, the fractional seconds tend to increase continually. Although the commands appear to be running in every Nth second, it actually takes a fraction longer. You can remove this by utilizing the -p option.

$ watch -n 3 -p echo, “Hello World.”

This command will run print the “Hello World” string every three precise seconds. You can use ntptime to find the fractional differences in running periods. The below example utilizes the long-styled syntax– accurate.

$ watch -n 3– exact echo “Hello World.”

10. Usage Exec Instead of sh -c.

You can pass the command offered to enjoy to exec instead of the more standard sh -c. This enables users to remove the requirement -f using quotes. Have a look at the following easy example to see how this works.

$ watch -n six -x echo hey there world.

Another advantage of using exec over sh is that it eliminates wrapper processes from the computer system’s memory with the real process. The long-styled kind for this alternative is– officer.

$ watch -n 6– exec echo hey there world.

11. Show Mails utilizing Linux Watch Command.

One great example of the watch energy is inspecting inbound emails. The following example shows users how to use the watch for monitoring emails straight from their terminal session.

$ watch -n 60 from.

The above command will look for new email messages when per minute. It leverages the energy to inspect whether there are any new messages or not.

12. Monitor Directory Contents for Changes.

The following basic example illustrates how we can utilize the watch utility to keep an eye on file system directories for content changes. It will print out the directory listing and highlight changes in the contents.

$ watch -d ls -l.

We can use the Linux grep command to filter out the output for a specific user only. The listed below command searches for modifications made by the user ‘ralph.’

$ watch -d ‘ls -l|grep ralph’.

You can place bigger commands inside quotes or utilize the backslash if trying to find a cleaner method.

$ watch -d \.

> ls -l|grep ‘ralph’.

13. Screen CPU Temperature Using Watch.

If you are utilizing an old laptop or a rusty computer system with heating concerns, you would need to keep the temperature level in check. You can utilize the watch utility in conjunction with the sensing units tool to monitor your computer system’s temperature level. Take a close take a look at the listed below example to see how this works.

$ watch -n 60 sensing units.

This command will inspect the core temperature level of your laptop or desktop when every minute. It will likewise let you know whether the current temperature level is vital so you can close down the system. Take a look at our previous guide on laptop computer overheating concerns to find out how to fix the problems.

14. Show the Version details.

The variation information of a tool helps admins identify the origin of the program and discover spots for bugs. You can see the variation data for the watch energy utilizing among the following easy commands.

$ watch -v.

$ view– variation.

15. Show the Help and Manual Page.

The help page of Linux terminal commands offers summarized info of all possible command-line choices and their usage. Feel free to check the aid page of the linux watch multiple commands if you desire fast details for a particular option.

$ watch -h.

$ watch– assistance.

Both of these options will display the help page and after that exit. On the other hand, seek advice from the manual page whenever you wish to discover a certain option in-details.

$ man watch.


The linux watch multiple commands watch command is a basic yet beneficial tool that has a lot of use cases. Admins can use it to set up tailored monitoring for often utilized terminal commands. In this guide, we have discussed all of the choices readily available to watch. We have likewise illustrated several practical examples to help readers master this tool. Hopefully, we could offer you all the vital details you were trying to find regarding this handy little tool. If you own any more questions or advice, leave them in the remark section, and we will get back to you.

You can also check over other articles like:

Related Articles

Back to top button