linux watch 文件大小,Linux命令之watch

watch

命令功能:

watch可以帮你监测一个命令的运行结果,省得你一遍遍的手动运行。

语法:

watch [-n] [-d] command

参数:

-n:指定时间间隔,默认为2s的时间间隔重复运行命令

-d:以高亮显示变化的区域

补充说明:

watch是一个非常实用的命令,基本所有的Linux发行版都带有这个小工具

直接在watch后面接你想运行的命令,watch就会帮你重复运行,并把每次的结果都更新在屏幕上。

Ctrl+c退出

你可以拿他来监测你想要的一切命令的结果变化,比如tail一个log文件,ls监测某个文件的大小变化等

命令实践:

[root@yubing tmp]# [root@yubing ~]# vi /server/scripts/yubing.sh

编写一个脚本,把当前时间精确到分钟数输入到文件

echo "$(date +%Y-%m-%d-%H-%M)" >>/tmp/yubing.txt

然后编写一个定时任务

[root@yubing ~]# crontab -e

# echo date to yubing.txt  every min每分钟执行一次脚本

* * * * /bin/sh /server/scripts/yubing.sh >/dev/null 2>&1

[root@yubing tmp]# ll

总计4

-rw-r--r-- 1 root root 20 05-08 10:42 yubing.txt

[root@yubing tmp]# cat yubing.txt

2013-05-08-10-42-01

2013-05-08-10-43-01

[root@yubing tmp]#

[root@yubing tmp]# watch cat yubing.txt

Every  2.0s: cat yubing.txt       Wed May  8 10:44:10 2013

每2秒执行一次cat命令当前系统时间并每2秒跳动一次

2013-05-08-10-42-01

2013-05-08-10-43-01

2013-05-08-10-44-01

ctrl+c退出

watch ll yubing.txt

sh: ll: command not found看来不能使用简写

-rw-r--r-- 1 root root 140 05-08 10:48 yubing.txt

一分钟后会替换成

-rw-r--r-- 1 root root 160 05-08 10:49 yubing.txt文件大小,时间都会变动

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值