The Linux watch command is a favorite among power users because it allows them to run a certain command on a regular basis and see the results in a terminal window. By using the Linux watch command, it allows users to track the changes in outputs at any time. This is beneficial to the application that utilizes the real-time view of events that is in the operating system. It will run the program every two seconds by default, however, you are able to customize the time frame using the “-n” or “-interval” options. In this article, we will be guiding you on how to utilize the Linux watch command on your Linux VPS server
Basic Watch Commands
Before using the watch commands in the terminal, access your VPS using SSH. Here is a basic syntax of the watch command.
watch <file_name>
Replace <file_name> with a file of your preference to run with the watch command. For example, to see the current date, run the following command.
watch date
We can see the date is updating every 2 seconds according to the current date and time system.
To stop the changes in the output, use the “-g” option to assist such as the following command below.
watch -g free
To turn off the header that shows the blank line, current time, command, and interval, use the “-t” option to assist you with the following command.
watch -t date
Use the ipconfig along with the watch command to allow you to observe your bandwidth statistic such as shown in the following command.
watch ipconfig
You should be able to see your network speed every 2 seconds.
To differentiate it with the update command, use the “-d” option as it will highlight the changes made in the watch command with the following command.
watch -d date
Change Time Intervals
To change the duration between every update by the watch command, use the “-n” option such as the following example.
watch -n 5 date
This will update the out every 5 seconds instead of 2 seconds, which is the default time interval.
Monitor Files
To monitor the status of files in real-time, run the following command.
watch -d 'ls -l | fgrep <user_name>'
Replace <user_name> with your username, the ls -l represents the files in the user directory.
Watch Command Clock
You can also use the watch command as a clock using the following command.
watch -t date
Monitor CPU Temperature
This is optional and you won’t be using it if you are using a VPS as the backend is usually handled by your hosting services. However, if you are using any other Linux-based machine, you may monitor the CPU temperature using the following command.
watch -n 1 sensors