根据这个问题+答案,您可以将其编写为管道脚本.管道是shell编程和shell脚本的一个组成部分.
find /path/to/files -type l -print | \
rsync -av --files-from=- /path/to/files user@targethost:/path
Run Code Online (Sandbox Code Playgroud)
这里发生了什么?
该find
命令从/ path/to/files开始,并以递归方式遍历该点下的所有内容.选项find
是限制-print
选项输出的条件.在这种情况下,只会打印-type l
(符号链接,根据man find
)的内容以找到"标准输出".
这些文件成为rsync
命令--file-from
选项的"标准输入" .
试一试.我实际上没有对此进行测试,但在我看来它应该可行.
您可以生成不包括链接的文件列表find input_dir -not -type l
,rsync 有一个选项--exclude-from=exlude_file.txt
你可以分两步完成:
find input_dir -not -type l > /tmp/rsync-exclude.txt
rsync -uvrl --exclude-from=/tmp/rsync-exclude.txt input_dir output_dir
一行bash:
rsync -urvl --exclude-from=<(find input_dir -not -type l | sed 's/^..//') input_dir output_dir