watch命令简介

watch命令可以重复的执行命令,并且将其输出在命令行上,可以方便的实现一些简单的监控

 watch -n 1 cat 1.txt

上面的这个命令输出1.txt的内容,-n 1表示每隔一秒钟执行一次命令


右侧shell执行命令,左侧是watch的输出

我们可以看到先是输出了wdnmd,然后输出了nmsl,至此,我们很简单的实现了一个不断变化的文件的监控,但它是实用的——比如监控一个动态变化的log日志

另一个小例子:在所有进程中查找是否有node关键字的进程,每隔三秒刷新一次

 watch -n 3 "ps aux | grep node"

example

EXAMPLESTo watch for mail, you might dowatch -n 60 fromTo watch the contents of a directory change, you could usewatch -d ls -lIf you're only interested in files owned by user joe, you might usewatch -d 'ls -l | fgrep joe'To see the effects of quoting, try these outwatch echo $$watch echo '$$'watch echo "'"'$$'"'"To see the effect of precision time keeping, try adding -p towatch -n 10 sleep 1You can watch for your administrator to install the latest kernel withwatch uname -r(Note that -p isn't guaranteed to work across reboots, especially in the face of ntpdate or other bootup time-changing mechanisms)

option

OPTIONS-d, --differences [permanent]Highlight the differences between successive updates.  Option will read optional argument that changes highlight to be  permanent,  allowing  tosee what has changed at least once since first iteration.-n, --interval secondsSpecify  update  interval.  The command will not allow quicker than 0.1 second interval, in which the smaller values are converted. Both '.' and',' work for any locales.-p, --preciseMake watch attempt to run command every interval seconds. Try it with ntptime and notice how the fractional seconds stays (nearly) the same,  asopposed to normal mode where they continuously increase.-t, --no-titleTurn off the header showing the interval, command, and current time at the top of the display, as well as the following blank line.-b, --beepBeep if command has a non-zero exit.-e, --errexitFreeze updates on command error, and exit after a key press.-g, --chgexitExit when the output of command changes.-c, --colorInterpret ANSI color and style sequences.-x, --execPass command to exec(2) instead of sh -c which reduces the need to use extra quoting to get the desired effect.-h, --helpDisplay help text and exit.-v, --versionDisplay version information and exit.

watch命令实现Linux监控相关推荐

  1. linux 监控报文命令 nc,linux监控命令nc用法

    一.nc命令检测端口的用法 # nc -v -w 10 %IP% -z %PORT% -v 显示指令执行过程. -w 设置等待连线的时间. -u 表示使用UDP协议 -z 使用0输入/输出模式,只在扫 ...

  2. linux控制风扇转速的命令,关于linux监控硬件系统状态(如CPU温度,风扇转速等)

    1.安装相关的包需要4个包,分别为 dmidecode,lm_sensors,lm_sensors-devel,gnome-applet-sensors 命令:yum install dmidecod ...

  3. linux终端显示被覆盖,图文说明:Linux监控命令全覆盖

    原文出处: 凌风的博客   欢迎分享原创到伯乐头条 1.1 top 1.1.1 命令说明 Top 命令能够实时监控系统的运行状态,并且可以按照cpu.内存和执行时间进行排序 1.1.2 参数说明 命令 ...

  4. 20个命令行工具监控 Linux 系统性能(转载)

    1. top - Linux 系统进程监控 top 命令是性能监控程序,它可以在很多 Linux/Unix 版本下使用,并且它也是 Linux 系统管理员经常使用的监控系统性能的工具.Top 命令可以 ...

  5. Linux监控命令之 top

    top 简介 top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器.top是一个动态显示过程,即可以通过用户按键来不断刷新当前状态.如 ...

  6. 使用vmstat和iostat命令进行Linux性能监控

    使用vmstat和iostat命令进行Linux性能监控 这是我们正在进行的Linux命令和性能监控系列的一部分.vmstat和iostat两个命令都适用于所有主要的类unix系统(Linux/uni ...

  7. Linux命令进阶-cpu监控内存监控文件IO网络IO性能分析

    Linux命令进阶-cpu监控内存监控文件IO网络IO性能分析 前言 1 linux基础命令 1.1 grep 1.2 ls 1.3 find 1.4 ulimit 1.5 curl 1.6 scp ...

  8. linux 监控命令free,简单了解Linux性能监控命令free

    在系统遇到各种IO瓶颈,内存使用率高,cpu使用率高等问题时,我们如何来定位错误?linux提供了很多命令来协助我们快速定位到错误,free命令是Linux最常用的命令之一:它可以查看系统的内存状况, ...

  9. Linux监控命令之==top

    一.命令说明 top 命令能够实时监控系统的运行状态,并且可以按照CPU.内存和执行时间进行排序,同时top 命令还可以通过交互式命令进行设定显示,通过top 命令可以查看即时活跃的进行. 二.参数说 ...

最新文章

  1. java中字符与字节的编码关系
  2. Android 线程池概念及使用
  3. android 高级画布绘图
  4. 【杂项】原来有两种单引号(单引号和反引号)
  5. java tar 安装程序_linux下jdk的安装(tar包)
  6. ELK6.0部署:Elasticsearch+Logstash+Kibana搭建分布式日志平台
  7. python whl安装 缺少dll 查看具_解决Python安装时报缺少DLL问题【两种解决方法】
  8. matlab求微分方程的系数,Matlab中系数为离散值的微分方程求解【编辑完成求解答】...
  9. 学习Spring Boot前需要了解的Spring基础知识
  10. 第一节 如何用Go实现单链表
  11. 浏览器获取CA认证流程
  12. C++ 日期 时间
  13. C#中 JSON 序列化 与 反序列化
  14. EasyRecovery15永久免费数据恢复软件
  15. 使用美图秀秀批量处理照片
  16. JavaScript 中 List转Tree,Tree转List
  17. 琴生不等式与其他(Jensen Inequation)【粗】
  18. 6s测试信号软件,手机信号强度测试:苹果iPhone 6s不敌三星S6
  19. 《C语言点滴》一第1章 程序猿 程序媛1.1 装备篇
  20. 为什么计算机日期最早1970,计算机时间基准——1970.1.1

热门文章

  1. centos7安装gitlab并汉化
  2. 帝国CMS, PhpCMS 与 dedecms 的对比
  3. Java大王叫我来巡山呐
  4. Ubuntu20.04环境下MySQL8.0.30的 用户管理,设置修改密码,密码过期策略,权限管理,角色管理
  5. 20 | 拿到多家Offer应该如何选择
  6. LeetCode 49 反转字符串
  7. 2021年南阳市五中高考成绩查询,2021年南阳市高中排名
  8. Spring AOP 切面打印入参、响应、执行时间
  9. 如何安装swift server
  10. php(TP5)+redis实现秒杀抢购(不限制用户购买次数和限制用户购买次数)(附源码)