问题
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.
回答1:
Yes, it is easily possible.
folders are created dynamically that's why i want to skip username part and watch all folders with name Download.
fluffy is the right tool for it.
- Open a terminal:1, run
fluffy - In another terminal:2,
fluffyctl -W /storage/data/*/Download - You must be able to see events on terminal:1 where
fluffywas invoked. - 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/*/Downloadafter 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.
Commands for your use case:
dir contents -
root@six-k:/opt# ls /opt/*/d1
/opt/d1/d1:
fd1
/opt/dd2/d1:
fd1
/opt/dd3/d1:
invoke fluffy -
root@six-k:/home/lab/fluffy# fluffy
control/manage fluffy -
root@six-k:/opt# fluffyctl -W /opt/*/d1
events -
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
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!
来源:https://stackoverflow.com/questions/47673447/inotify-linux-watching-subdirectories