inotify-tools工具安装配置

inotify-tools工具安装配置

Inotify一种强大的、细粒度的、异步文件系统监控机制,它满足各种各样的文件监控需要,可以监控文件系统的访问属性、读写属性、权限属性、删除创建、移动等操作,也就是可以监控文件发生的一切变化。。

inotify-tools是一个C库和一组命令行的工作提供Linux下inotify的简单接口。inotify-tools安装后会得到inotifywait和inotifywatch这两条命令:

一、安装

1.从内核和目录里面查看是否支持inotify

[root@yaoji-dev-test ~]# uname -r
3.10.0-693.2.2.el7.x86_64

2.6.13以上版本内核都会支持
ls -l /proc/sys/fs/inotify/ -→主要查看下面有没有三个文件

inotify-tools工具安装配置

2.检查是否有安装inotify 如果没有就安装

rpm -qa inotify-tools
安装命令为:
yum install inotify-tools -y

二、 参数详解

安装完成后会生成两个命令
/usr/bin/inotifywait
/usr/bin/inotifywatch

  • inotifywait命令可以用来收集有关文件访问信息,Linux发行版一般没有包括这个命令,需要安装inotify-tools,这个命令还需要将inotify支持编译入Linux内核,好在大多数Linux发行版都在内核中启用了inotify。
  • inotifywatch命令用于收集关于被监视的文件系统的统计数据,包括每个 inotify 事件发生多少次

    inotifywait命令参数:

    • -m是要持续监视变化。
    • -r使用递归形式监视目录。
    • -q减少冗余信息,只打印出需要的信息。
    • -e指定要监视的事件列表。
    • --timefmt是指定时间的输出格式。
      FMT: # --timefmt '%y-%m-%d %H:%M'
    • --format指定文件变化的详细信息。
      FMT: # --format '%T %f %e'
    • --outfile将事件输出到指定文件,而不输出到屏幕
    • -d|--daemon以守护进程方式后台运行(除了在后台运行外,与-m选项一样)

可监听的事件:

Events:

        access          file or directory contents were read   访问

        modify          file or directory contents were written  修改

        attrib          file or directory attributes changed  属性发生变化

        close_write     file or directory closed, after being opened in  写入之后关闭

                        writeable mode

        close_nowrite   file or directory closed, after being opened in  

                        read-only mode

        close           file or directory closed, regardless of read/write mode 

        open            file or directory opened

        moved_to        file or directory moved to watched directory  移动到哪里

        moved_from      file or directory moved from watched directory

        move            file or directory moved to or from watched directory

        create          file or directory created within watched directory

        delete          file or directory deleted within watched directory

        delete_self     file or directory was deleted

        unmount         file system containing file or directory unmounted卸载

三、使用示例

监听/tmp目录内所有文件和目录的"增删改"操作
/usr/bin/inotifywait -mrq -e 'create,delete,close_write,attrib,moved_to' --timefmt '%Y-%m-%d %H:%M' --format '%T %f %e' /tmp/

2018-05-21 19:53 xiaoke.txt CREATE
2018-05-21 19:53 xiaoke.txt ATTRIB
2018-05-21 19:53 xiaoke.txt CLOSE_WRITE,CLOSE
2018-05-21 19:54 xiaoke.txt DELETE
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值