我在 bash 脚本中使用 rsync 来保持几个服务器和 NAS 之间的文件同步。我遇到的一个问题是尝试生成在 rsync 期间已更改的文件列表。
这个想法是,当我运行 rsync 时,我可以将已更改的文件输出到文本文件中 - 更希望内存中有一个数组 - 然后在脚本存在之前,我可以只对已更改的文件运行 chown 。
有没有人找到一种方法来执行这样的任务?
# specify the source directory
source_directory=/Users/jason/Desktop/source
# specify the destination directory
# DO NOT ADD THE SAME DIRECTORY NAME AS RSYNC WILL CREATE IT FOR YOU
destination_directory=/Users/jason/Desktop/destination
# run the rsync command
rsync -avz $source_directory $destination_directory
# grab the changed items and save to an array or temp file?
# loop through and chown each changed file
for changed_item …
Run Code Online (Sandbox Code Playgroud)