初始化Linux监视子目录 [英] Inotify linux watching subdirectories

查看:102
本文介绍了初始化Linux监视子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以按这种模式监视目录/storage/data/usernames/Download/->/storage/data/*/Download/我需要监视是否在每个用户的Download文件夹中进行了更改.也许我需要创建所有路径的列表,将其放置在数组中,并使用循环启动来初始化每个文件夹上的进程,但这对系统而言可能很沉重.

is it possible to watch directories in this pattern /storage/data/usernames/Download/ -> /storage/data/*/Download/ I need to watch if changes are made in Download folder of each user. Maybe i need to create list of all paths, put it in array and with loop start inotify processes on each folder, but this may be to heavy for system.

推荐答案

是的,很容易做到.

文件夹是动态创建的,这就是为什么我要跳过用户名 分开并查看所有名称为Download的文件夹.

folders are created dynamically that's why i want to skip username part and watch all folders with name Download.

蓬松是正确的工具.

  1. 打开终端:1,运行fluffy
  2. 在另一个终端中:2,fluffyctl -W /storage/data/*/Download
  3. 您必须能够在调用fluffy的终端:1上看到事件.
  4. 无论何时添加新用户但不希望重新执行蓬松更新路径,请在添加新用户后再次运行相同的watch命令.选择具有相同设置/选择的新用户目录.如果您删除了任何用户,则不必费心,蓬松的对象将自行释放资源.
  1. Open a terminal:1, run fluffy
  2. In another terminal:2, fluffyctl -W /storage/data/*/Download
  3. You must be able to see events on terminal:1 where fluffy was invoked.
  4. When ever you add a new user but wish not to reexecute fluffy to update the path, run the same watch command again fluffyctl -W /storage/data/*/Download after you have added a new user; picks up the new user directory with the same settings/choices. If you have removed any user, don't have to bother, fluffy takes care of releasing the resources by itself.

您的用例命令:

目录内容-

root@six-k:/opt# ls /opt/*/d1
/opt/d1/d1:
fd1

/opt/dd2/d1:
fd1

/opt/dd3/d1:

调用fluffy-

root@six-k:/home/lab/fluffy# fluffy

控制/管理蓬松-

root@six-k:/opt# fluffyctl -W /opt/*/d1

事件-

root@six-k:/home/lab/fluffy# fluffy

event:  ACCESS, ISDIR, 
path:   /opt/d1/d1

event:  CLOSE_NOWRITE, ISDIR, 
path:   /opt/d1/d1

event:  ACCESS, ISDIR, 
path:   /opt/dd2/d1

event:  CLOSE_NOWRITE, ISDIR, 
path:   /opt/dd2/d1

event:  ACCESS, ISDIR, 
path:   /opt/dd3/d1

event:  CLOSE_NOWRITE, ISDIR, 
path:   /opt/dd3/d1

注意: inotifywait并不优雅,它有错误,并报告错误的事件路径.我不想在这里查看inotifytools,但是如果您想知道它有什么问题,请查看目录树并在其中进行重命名/移动.稍后在重命名的目录上执行ls,查看其报告的路径!

Note: inotifywait is not elegant, it is buggy and reports false event paths. I do not wish to review inotifytools here, but if you are curious to know what is wrong with it, watch a directory tree and perform renames/moves with in it. Later do an ls on that renamed directory, see what path it reports!

这篇关于初始化Linux监视子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆