Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何通过rsync仅复制符号链接_Linux_Unix_Rsync_Symlink - Fatal编程技术网

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

Linux 如何通过rsync仅复制符号链接,linux,unix,rsync,symlink,Linux,Unix,Rsync,Symlink,如何使用rsync仅复制符号链接(而不是它指向的文件)或其他文件 我试过了 rsync-uvrl输入\u目录输出\u目录 但我只需要复制符号链接 使用include exclude选项的任何技巧?根据,您可以将其脚本化为管道。管道是shell编程和shell脚本的组成部分 find /path/to/files -type l -print | \ rsync -av --files-from=- /path/to/files user@targethost:/path 这里发生了什么事?

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

我试过了

rsync-uvrl输入\u目录输出\u目录

但我只需要复制符号链接

使用include exclude选项的任何技巧?

根据,您可以将其脚本化为管道。管道是shell编程和shell脚本的组成部分

find /path/to/files -type l -print | \
  rsync -av --files-from=- /path/to/files user@targethost:/path
这里发生了什么事?

find
命令从/path/to/files开始,递归地遍历该点下的所有内容。
查找
的选项是限制
-print
选项输出内容的条件。在这种情况下,只有
-类型l
(符号链接,根据
人工查找
)的东西将被打印到查找的“标准输出”

这些文件成为
rsync
命令的
--file from
选项的“标准输入”


试试看。我还没有实际测试过这个,但在我看来它应该可以工作。

您可以生成一个文件列表,其中不包括带有
find input\u dir-not-type l的链接,rsync有一个选项
--exclude from=exlude\u file.txt

您可以通过两个步骤完成此操作:

find input\u dir-not-type l>/tmp/rsync exclude.txt

rsync-uvrl--exclude from=/tmp/rsync-exclude.txt input\u dir output\u dir

一行bash:


rsync-urvl--exclude from=您可以更轻松地执行以下操作:

find /path/to/dir/ -type l -exec rsync -avP {} ssh_server:/path/to/server/ \;
编辑: 如果您只想复制当前目录的符号链接,而不想使其递归。你可以做:

find /path/to/dir/ -maxdepth 1 -type l -exec rsync -avP {} ssh_server:/path/to/server/ \;
我喜欢这样:

find ./ -type l -print > /tmp/list_of_links.txt
rsync -av --files-from=/tmp/list_of_links.txt /path/to/files user@targethost:/path

原因很简单。在之前建议的版本中,我必须在每个文件中输入密码。这样我可以一次发送所有符号链接,只需输入一个密码

但这不会将符号链接复制为符号链接。@Dan。。。嗯,
-a
转换为
-rlptgoD
-l
被记录为“遇到符号链接时,在目标上重新创建符号链接。”您遇到了什么结果?哦!我错过了-a包括-l!