EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

Linux Watch Command

By Priya PedamkarPriya Pedamkar

Home » Software Development » Software Development Tutorials » Linux Tutorial » Linux Watch Command

Linux Watch Command

Introduction to Linux Watch Command

In the Linux operating system, the watch command is used to run any command in the environment and print the output of the command on the working bash terminal or CLI. The major use of watch command is to print the output difference in between the command i.e. if we are printing the same command multiple times and we need to check the output difference of the same command then we need to use the watch command.

In 1991, the innovative watch command was written by Tony Rems (email address: rembo@unisoft.com) after that it will modify and corrected by Francois Pinard. After the time interval, there are lots of changes happen in utility.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax :

watch [ options ] command

  • watch: We can use the “watch” keyword in the syntax or command. It will take different arguments like options and the Linux commands. As per the provided arguments or options, it will print the command output on the screen.
  • options: We can provide the different flags as the option that is compatible with the “watch” command.
  • command: We can use the different Linux commands.

How does Linux Watch command work?

In the Linux environment, we are having multiple ways to print the command in a specific interval of time. But in the watch command, we are printing the command output rapidly and observe the command output difference if any.

In Watch command below are the different exit codes available in it.

  • 0: Once the job or command was successfully executed then it will print the “0” exit code.
  • 1: Once the job or command failures then it will print the “1” exit code.
  • 2: when the job or command forking the process to watch the failed then it will print the “2” exit code.
  • 3: When it will replace the child process of stdout with write side pipe failed then it will print the “3” exit code.
  • 4: When the command execution was failed then it will print the “4” exit code.
  • 5: When we will closing the child process write pipe failed then it will print the “5” exit code.
  • 6: When the IPC pipe creation failed then it will print the “7” exit code.
  • Other: It will watch the command or job and will propagate command exit status as the child exit status.

Below are the lists of options that are compatible with the watch command.

Sr No Option Description
1 -d, –differences [permanent] It will help to highlight the differences between successive updates on the job or command level. It will print the information or update if anything may change the successful execution of the command or job. What has changed at least once since the first iteration?
2 -n, –interval seconds It will help to Specify the update interval.

Note: But the command will not allow quicker than 0.1-second interval in which the smaller values are converted.

3 -p, –precise It will make sure that the watch attempt to run the command every interval seconds. We need to sync with the system ntptime and notice how the fractional seconds stay (nearly) the same.
4 -t, –no-title It will help to turn off the header showing the current time command, interval, at the top of the display.
5 -b, –beep The beep is the command has a non-zero exit.
6 -e, –errexit It will freeze the updates on command error and exit after an input or key press.
7 -g, –chgexit It will exit when the output of command changes.
8 -c, –color It will interpret the ANSI color and style sequences.
9 -x, –exec The –exec option, which passes the command to exec (2) instead.
10 -h, –help It will display the help information and exit it
11 -v, –version It will print the version information and exit it

Examples to Implement Linux Watch Command

In the Linux environment, it is a very easy and simple way to use the Watch command.

Popular Course in this category
Linux Training Program (16 Courses, 3+ Projects)16 Online Courses | 3 Hands-on Projects | 160+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (6,008 ratings)
Course Price

View Course

Related Courses
Kali Linux Training (3 Courses, 3+ Projects)Red Hat Linux Training Program (4 Courses, 1+ Projects)

Example #1 – Linux Watch Command

Command :

watch date

Explanation:

As per the above command, we are trigging the date command with watch keyword. The command output window will appear as it is unless and until we do not kill it (via Ctrl+c option).

Output :

Linux Watch Command 1-1 

Example #2 – Change Time Interval

In watch command, we can the command execution time. We need to use the “-n” option with it.

Command:

watch -n 5 date

Explanation:

As per the above command, we are changing the command execution time in second. The date command will run every 5 seconds.

Output:

Linux Watch Command 1-2

Example #3 – Command Difference

In watch command, we are having the functionality to get the difference in between the command output.

Command:

watch -d date

Explanation:

In watch command, we are able to find the command difference on the CLI window. The command difference will highlight by the watch command.

Output:

command difference on the CLI window

Example #4 – Omit Header Information

In watch command, we are able to remove the header information from the command output.

Command:

watch -t date

Explanation:

As per the above command, we are removing the header information of the watch command.

Output:

watch command 4 

Example #5 – Auto Exit if Command Output Change

In watch command, we are having the functionality to exit the output window when the command output was changed.

Command:

watch -g date

Explanation:

In screenshot 1 (a), we are seeing the watch command output. But when command difference is observed then the screen exit automatically (refer screenshot 1 (b)).

Output:

Screenshot 1 (a)

Auto Exit if Command Output Change

Screenshot 1 (b)

root watch

Conclusion

We have seen the uncut concept of “Linux Watch Command” with the proper example, explanation and command with different outputs. As per the requirement, we can change the command execution time in watch command. It is very useful to observe the command difference.

Recommended Article

This is a guide to Linux Watch Command. Here we discuss an overview on the Linux Watch Command and its different commands along with Examples and Code Implementation. You can also go through our other suggested articles to learn more –

  1. Linux Automount
  2. Linux bg Command
  3. Linux tracepath
  4. Linux Mount Command

Linux Training Program (16 Courses, 3+ Projects)

16 Online Courses

3 Hands-on Projects

160+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
Linux Tutorial
  • Linux Commands
    • CAT Command in Linux
    • PS command in Linux
    • Mkdir Command in Linux
    • rmdir command in Linux
    • mv command in Linux
    • Linux rm Command
    • CHMOD Command in Linux
    • Zip Command in Linux
    • Linux Route Command
    • SCP Command in Linux
    • du Command in Linux
    • Less Command in Linux
    • Copy Command in Linux
    • Head Command in Linux
    • Help Command in Linux
    • Linux History Command
    • hostname Command in Linux
    • GREP Command in Linux
    • Linux Curl Command
    • Linux List Users
    • Linux List Directories
    • Linux Directory Permissions
    • Find Directory Linux
    • Linux User Permission
    • Linux Add User
    • Linux Delete User
    • Linux uniq
    • Linux Filter Commands
    • Linux sort Command
    • Linux Sort by Size
    • Remove dir Linux
    • Linux tr Command
    • Linux Touch Command
    • Linux More Command
    • Linux Cal Command
    • Linux OD
    • Linux Zcat
    • Linux tracepath
    • Linux Sleep
    • Linux bg Command
    • Linux WC
    • Linux Read
    • Linux Write
    • Linux Rename Command
    • Linux Free Command
    • Linux tac
    • Linux Shred
    • Linux wget
    • Linux Date
    • Linux Untar
    • Linux JQ
    • Linux Xargs
    • Linux Mount Command
    • Linux mdadm
    • Linux comm
    • Linux tee Command
    • Tail Command in Linux
    • Linux gzip
    • Linux Directory Structure
    • Linux Alias Command
    • Linux Inode
    • Linux Ping
    • Linux Watch Command
    • Linux Split Command
    • Linux Size
    • Linux Network Stack
    • Linux Diff Command
    • Vim Command in Linux
    • Linux nslookup
  • Basic
    • Introduction to Linux
    • What is Linux
    • Careers in Linux
    • How to Install Linux
    • How to Install Ubuntu
    • How to Install Ubuntu Server
    • How To Install Debian
    • Advantage Of Linux
    • What is Raid in Linux
    • What is Raid 5?
    • Raid 5 vs Raid 6
    • Careers in Linux Administration
    • What is Shell in Linux?
    • Bash Shell in Linux
    • Linux Emulator
    • Linux Operators
    • Linux Apps
    • Linux Keyboard Shortcuts
    • Linux Crontab
    • What is Raid Storage
    • What is Vmware
    • What is RedHat
    • What is Debian
    • Uses of Ubuntu
    • Career In RedHat
    • Linux Distributions
    • Linux From Scratch
    • Linux Format
    • Cheat Sheet Linux
  • Advanced
    • Install VMware
    • Install GRUB
    • Chown Command in Linux
    • Linux Network Command
    • Configuring Linux Network Environment
    • DNS Configuration in Linux
    • Linux Users
    • Create User in Linux
    • DHCP Server in Linux
    • FTP Server in Linux
    • Linux Regular Expression
    • IP Command in Linux
    • Set IP Address in Linux
    • Tar Command in Linux
    • Dynamic Host Configuration Protocol
    • Linux Kill Signals
    • Linux File Permissions
    • Linux File System
    • Linux Create File
    • Linux Concatenate Files
    • Linux Join
    • Linux Process Management
    • Linux Proxy Server
    • Linux System Commands
    • Linux System Logging
    • NFS in Linux
    • Linux LVM
    • Linux Repository
    • Samba Server in Linux
    • Top Commands in Linux
    • Types of Shells in Linux
    • Shell Script Types For Linux
    • GCC Command in Linux
    • Monolithic Kernel
    • YARN Package Manager
    • Linux Sed Replace
    • Linux List Groups
    • Linux Container
    • Linux Find File by Name
    • Create Folder in Linux
    • Linux Move Folder
    • Linux Error Codes
    • Linux Automount
    • Linux HugePages
  • Kali Linux
    • Install Kali Linux
    • Kali Linux Uses
    • Kali Linux Commands
    • Kali Linux Repository
    • Kali Linux Packages
    • Kali Linux root password
    • Kali Linux Alternative
  • Interview Questions
    • Linux Interview Questions
    • Linux System Administration Interview
    • Red Hat Interview Questions

Related Courses

Kali Linux Training

Linux Training Course

Red Hat Training Course

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - Linux Training Program (16 Courses, 3+ Projects) Learn More