watch Command in Linux

Learn via video courses
Topics Covered

Build an AI-First Career, Master the Complete Skillset

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program
NSDC Certified

AI Forward Deployed Engineer Program

Full-stack engineering, production AI and client-facing consulting

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program

Overview

Linux, with its wide array of commands and utilities, allows users to accomplish tasks with efficiency and flexibility. One of these utilities is the 'watch' command. The watch command in Linux is a powerful tool for periodically executing a command and then displaying the output in a standard shell. This can be incredibly useful for tracking changes in file directories, system status checks, or any scenario where you need to monitor the changes of a command's output over time.

Syntax of watch Command in Linux

The basic syntax of the watch command in Linux is as follows:

Where:

  • watch: This is the actual command to initiate the process.
  • options: These are optional adjustments to the command's functionality, such as changing the interval between command executions.
  • command: The command that watch will execute periodically.
Sharpen Your Fundamentals with Free Learning

Options in watch Command in Linux

  1. -n, --interval: Specify update interval. By default, watch will update every 2 seconds.

    For example -

    Output:

    This command will run the 'date' command every 1 second, instead of the default 2 seconds.

  2. -d, --differences: Highlights the differences between successive updates.

    For example -

    Output:

    This command will highlight the changes in the 'ls' command's output every 2 seconds.

  3. -t, --no-title: Turns off the header showing the interval, command, and current time.

    For example -

    Output:

    This command will run the 'date' command without the header information.

How Scaler Transformed Careers in Different Fields

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Example Usages

  • Watching the contents of a directory:

    Output:

    Explanation: This command will display the changes in a directory every 2 seconds.

  • Monitoring system processes:

    Output:

    Explanation: This command will display the current active processes every 2 seconds.

Tips

  • Watch command is not just limited to the basic Linux commands, it can be combined with pipes and redirections for more complex tasks.

  • It is possible to use the watch command with 'sudo' to monitor tasks that require administrator permissions.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Advanced Use Cases of watch Command in Linux

  • Monitoring changes in network connections:

    Output:

    Explanation: This command will display the changes in network connections every 2 seconds.

  • Displaying changes in disk usage:

    Output:

    Explanation: This command will display changes in disk usage every 2 seconds.

  • Monitoring changes in a specific file:

    Output:

    Explanation: This command will display any changes in 'myfile.txt' every 5 seconds.

Conclusion

  • The watch command in Linux is a powerful tool for monitoring changes over time.

  • It executes a command periodically, displaying its output and errors (the first screenfull).

  • It provides a dynamic real-time view on the output of a series of commands.