如何通过rsync仅复制符号链接

New*_*iee 9 unix linux symlink rsync

如何使用rsync仅复制符号链接(而不是它指向的文件)或其他文件?

我试过了

rsync -uvrl input_dir output_dir

但我只需要复制符号链接吗?

任何使用包括排除选项的技巧?

gho*_*oti 8

根据这个问题+答案,您可以将其编写为管道脚本.管道是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选项的"标准输入" .

试一试.我实际上没有对此进行测试,但在我看来它应该可行.


mou*_*oul 6

您可以生成不包括链接的文件列表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