![linux基本命令示例](https://img-blog.csdnimg.cn/img_convert/f54b30fc1bf69918a333e0954d44d92f.png)
linux基本命令示例
Some time generally long-running operations like copying disk need to track the change like disk usage or change of the size of the file. We generally run the same command again and again but this is a very cumbersome way yo see progress. Linux users created a “watch” application to make things better. When we use “watch” we can get change with specified interval times.
通常,某些长时间运行的操作(例如复制磁盘)需要跟踪更改(例如磁盘使用情况或文件大小的更改)。 我们通常会一次又一次地运行相同的命令,但这是您看到进度的非常麻烦的方式。 Linux用户创建了一个“监视”应用程序来使事情变得更好。 当我们使用“手表”时,我们可以在指定的间隔时间内进行更改。
句法 (Syntax)
We will use options to change behavior of the watch
command. COMMAND is the command we want to run with given intervals.
我们将使用选项来更改watch
命令的行为。 COMMAND是我们要以给定间隔运行的命令。
watch [OPTIONS] COMMAND
帮帮我 (Help)
We can print help information about the watch
command with the -h
option.
我们可以使用-h
选项打印有关watch
命令的帮助信息。
$ watch -h
![Help](https://img-blog.csdnimg.cn/img_convert/bddc93081a25aa5e176207c3b1ee927b.png)
只是看(Just Watch)
We will use watch
command without providing any options. We will provide ls -lh
command and run this command at 2 seconds interval. The default interval is 2 seconds.
我们将使用watch
命令,而不提供任何选项。 我们将提供ls -lh
命令,并以2秒的间隔运行该命令。 默认间隔为2秒。
$ watch ls -lh
![Just Watch](https://img-blog.csdnimg.cn/img_convert/39a4ed4e7566b5a22177ec41c8e5edd1.png)
As we can see from screenshot all files and folders are listed and will be refreshed in 2 seconds interval.
正如我们从屏幕快照中看到的,所有文件和文件夹都被列出,并且将在2秒的间隔内刷新。
退出或退出 (Exit or Quit)
While running watch
it will not end automatically. We must kill the watch
process if we want to end. The simple way to end watch
is using the following shortcut.
跑步时, watch
不会自动结束。 如果要结束,我们必须取消watch
程序。 结束watch
的简单方法是使用以下快捷方式。
CTRL+c
设定间隔 (Set Interval)
Default interval value for the watch is 2 seconds. In each interval provided command runs and the output is refreshed. We may need to change 2 seconds interval more suitable for our situation. -n
option can be used to change the default interval. We change ls -lh
command interval to 5 seconds in the following example.
手表的默认间隔值为2秒。 在提供的每个间隔中,将运行命令并刷新输出。 我们可能需要更改2秒间隔更适合我们的情况。 -n
选项可用于更改默认间隔。 在以下示例中,我们将ls -lh
命令间隔更改为5秒。
$ watch -n 5 ls -lh
![Set Interval](https://img-blog.csdnimg.cn/img_convert/f52905103e9bf7dabc81efeaa3d46c5f.png)
删除标题(Remove Header)
We can remote the watch title so we just get command output if we want to use the output from different applications.
我们可以远程监视手表标题,因此,如果我们要使用来自不同应用程序的输出,则只获取命令输出。
$ watch -t ls -lh
![Remove Header](https://img-blog.csdnimg.cn/img_convert/18a07b883b1c4e6e358253a27c83b2a9.png)
如有更改,请播放提示音(Play Beep If There Is Change)
As watch commands run provided command periodically. If there is no change the provided command provides 0 as output. If there is change there will be a non zero change which means there is a change. wait command can play a beep sound if the output is non-zero. We will provide the -b
or --beep
option.
当watch命令定期运行提供的命令时。 如果没有更改,提供的命令将提供0作为输出。 如果有变化,将有一个非零变化,这意味着有变化。 如果输出非零,则wait命令可以播放哔声。 我们将提供-b
或--beep
选项。
$ watch -b ls /home/ismail
![Play Beep If There Is Change](https://img-blog.csdnimg.cn/img_convert/2826ca557522d61329f3080533039c00.png)
带有示例信息图Linux Watch命令教程 (Linux Watch Command Tutorial With Examples Infographic)
![Linux Watch Command Tutorial With Examples Infographic](https://img-blog.csdnimg.cn/img_convert/92bd7969875f413c4c746700734ca1a4.png)
翻译自: https://www.poftut.com/linux-watch-command-tutorial-with-examples/
linux基本命令示例