使用 watch 每秒复制目录中的新文件两次
Use watch to copy new files in directory twice a second
我有一个文件夹 (foo),我想每秒检查两次。如果该文件夹中有任何新文件,我想将其复制到第二个文件夹 (foo2)。我想使用 watch 和 cp。我正在使用 tcsh。
如何操作?
这就是我正在尝试的:
touch lastChanged
watch --interval=.5 'if [[ $(ls foo) ]] then cp $; else echo "nothing new";fi
这似乎对我有用。我愿意接受更好的答案。
touch lastChecked
watch --interval=.5 'if [[ $(find foo -newer lastChecked -ls -exec cp {} foo2 \; then touch lastChecked; else echo "nothing new"; fi
手表每秒检查两次。
查找查找比 "lastChecked" 文件更新的文件并复制这些文件。
然后触摸 lastChecked。
触摸 lastChecked 也将允许在文件更新后进行 cping。
我有一个文件夹 (foo),我想每秒检查两次。如果该文件夹中有任何新文件,我想将其复制到第二个文件夹 (foo2)。我想使用 watch 和 cp。我正在使用 tcsh。
如何操作?
这就是我正在尝试的:
touch lastChanged
watch --interval=.5 'if [[ $(ls foo) ]] then cp $; else echo "nothing new";fi
这似乎对我有用。我愿意接受更好的答案。
touch lastChecked
watch --interval=.5 'if [[ $(find foo -newer lastChecked -ls -exec cp {} foo2 \; then touch lastChecked; else echo "nothing new"; fi
手表每秒检查两次。
查找查找比 "lastChecked" 文件更新的文件并复制这些文件。
然后触摸 lastChecked。
触摸 lastChecked 也将允许在文件更新后进行 cping。