find -newer 仅检测新复制的文件
我正在使用以下代码,
if [ ! -f $time_mark ]
then
touch $time_mark
fi
cp -f aaa.txt bbb.txt ccc.txt $file_dir
find $file_dir -newer $time_mark > file_list.txt
...
我使用 find -newer 仅发送晚于 $time_mark 复制的文件。但事实证明,如果$time_mark第一次不存在,它将执行touch $time_mark并开始复制文件,这几乎可以同时发生。这会导致 $time_mark 和复制的文件具有相同的系统时间,并且仅发送晚于 $time_mark 复制的文件的整个概念不起作用。
有什么方法可以解决这个问题吗?
谢谢
I am using the following code
if [ ! -f $time_mark ]
then
touch $time_mark
fi
cp -f aaa.txt bbb.txt ccc.txt $file_dir
find $file_dir -newer $time_mark > file_list.txt
...
I am using find -newer to send only files are that copied later than $time_mark. But it turns out that if $time_mark does not exist for first time, it will execute touch $time_mark and start copying files, which can happen almost at the same time. This results in $time_mark and copied files having the same system time, and the whole concept of sending only files copied later than $time_mark doesn't work.
Is there some way to work around this problem?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更好的是似乎有条件地执行触摸(仅当先前运行成功时?)
我强烈建议查看 rsync、rdiff-backup 或其他(备份?)理解增量变化检测的工具。
作为一个非常简单的措施,因为您似乎暗示您想要将这些文件(?)复制到某个地方,只需使用
-pu
进行复制(--preserve=mode,ownership,timestamps --update
)可以做到这一点Even better would seem to execute the touch conditionally (only if the prior run succeeded?)
I strongly suggest to look at
rsync
,rdiff-backup
, or other (backup?) tools that grok incremental change detection.As a very simple measure, since you seem to hint you want to copy these files (?) somewhere, simply copying with
-pu
(--preserve=mode,ownership,timestamps --update
) could do the trick不要忘记使用“cp -p”来保留原始文件的时间戳。
Don't forget to use "cp -p" to preserve timestamps of the original files.