Questions tagged «inotify»


1
inotifywait-重命名时获取新旧文件名
我正在寻找一种检测文件重命名并获取新旧文件名的可靠方法。这是我到目前为止的内容: COUNTER=0; inotifywait -m --format '%f' -e moved_from,moved_to ./ | while read FILE do if [ $COUNTER -eq 0 ]; then FROM=$FILE; COUNTER=1; else TO=$FILE; COUNTER=0; echo "sed -i 's/\/$FROM)/\/$TO)/g' /home/a/b/c/post/*.md" sed -i 's/\/'$FROM')/\/'$TO')/g' /home/a/b/c/post/*.md fi done 它可以工作,但是它假定您永远不会将文件移入或移出监视文件夹。它还假定事件成对出现,首先是move_from,然后是move_to。我不知道这是否总是对的(到目前为止有效)。 我读过inotify使用cookie链接事件。可以通过某种方式访问​​Cookie吗?缺少cookie,我考虑过使用时间戳将事件链接在一起。以更可靠的方式获取FROM和TO的任何提示吗? 完整脚本要点。
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.