如何使用 scp 从远程服务器复制目录,不包括特定的子目录
How to copy directory from remote server with scp, excluding a specific subdirectory
我有一个目录要从远程服务器复制到我的桌面。在这个目录中有一个 40Gb 的子目录,我想从复制中排除。到目前为止,我使用了 scp
命令,但在 man
页面中没有 -exclude
选项或任何类似的选项。通过在线查看,我发现了很多不同的方法来从远程主机复制目录或在本地复制时排除子目录,但没有办法将这两者结合起来。任何帮助表示赞赏。谢谢
要复制排除某些文件或文件夹,您应该尝试 rsync 命令。
有 --exclude-dir 选项可以用来排除子目录。
如果您不能使用 rsync(例如在只读系统上),另一个选择是 tar 通过 ssh。
tar \
--exclude='temp' \
--exclude='work' \
--exclude='logs' \
-cpf \. # c: create p: preserve owner f: dest file... is output stream
- \
apache-tomcat-9.0.17 \. # file or folder to compress/send through ssh
| ssh foo@bar.com '(cd ~/my/save/directory; tar xfp - )'
我有一个目录要从远程服务器复制到我的桌面。在这个目录中有一个 40Gb 的子目录,我想从复制中排除。到目前为止,我使用了 scp
命令,但在 man
页面中没有 -exclude
选项或任何类似的选项。通过在线查看,我发现了很多不同的方法来从远程主机复制目录或在本地复制时排除子目录,但没有办法将这两者结合起来。任何帮助表示赞赏。谢谢
要复制排除某些文件或文件夹,您应该尝试 rsync 命令。
有 --exclude-dir 选项可以用来排除子目录。
如果您不能使用 rsync(例如在只读系统上),另一个选择是 tar 通过 ssh。
tar \
--exclude='temp' \
--exclude='work' \
--exclude='logs' \
-cpf \. # c: create p: preserve owner f: dest file... is output stream
- \
apache-tomcat-9.0.17 \. # file or folder to compress/send through ssh
| ssh foo@bar.com '(cd ~/my/save/directory; tar xfp - )'