小编Jas*_* M.的帖子

如何从 rsync 输出已更改文件的列表?

我在 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)

scripting bash rsync

33
推荐指数
3
解决办法
6万
查看次数

标签 统计

bash ×1

rsync ×1

scripting ×1