[英]find -newer to detect only newly copied files
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 .我正在使用find -newer仅发送晚于$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.
但事实证明,如果$time_mark第一次不存在,它会执行touch $time_mark并开始复制文件,这几乎可以同时发生。 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.
这导致$time_mark和复制的文件具有相同的系统时间,并且仅发送晚于$time_mark复制的文件的整个概念不起作用。
Is there some way to work around this problem?有没有办法解决这个问题?
Thanks谢谢
if [ -f $time_mark ]
then
incremental="-newer $time_mark"
else
incremental=""
touch $time_mark
fi
...
find $file_dir $incremental > file_list.txt
...
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.我强烈建议查看
rsync
、 rdiff-backup
或其他(备份?)工具,这些工具可以了解增量更改检测。
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作为一个非常简单的措施,由于您似乎暗示要在某处复制这些文件(?),只需使用
-pu
( --preserve=mode,ownership,timestamps --update
)复制就可以了
Don't forget to use "cp -p" to preserve timestamps of the original files.不要忘记使用“cp -p”来保留原始文件的时间戳。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.