ssh user@server "sudo tar -czf - -C /path/To/Directory *.properties" | tar xzf -
失败并出现以下错误 -
tar: *.properties: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
如果我 ssh 到服务器,然后在服务器上,而不是使用 tar -czf -
使用 tar -czf abc.tgz
并删除最后的管道命令,它工作正常,即压缩目录中的所有 .properties 文件?
我尝试过使用 --wildcards 参数以及 -P 和以 *.properties 结尾的完整路径,但它们也不起作用。
最佳答案
远端的 shell 在执行 tar
之前会扩展 用户
的主目录中的 *.properties。我猜测 ~user
中没有匹配的文件。
您可能想要的更像是(假设用户
可以访问该目录)
ssh user@server 'cd /path/To/Directory && sudo tar -czf - *.properties' \
| tar xzf -
或者,使用 tar
的 --wildcards
选项,并停止远程 shell 扩展参数:
ssh user@server 'sudo tar -czf - -C /path/To/Directory --wildcards \*.properties'
关于bash - 为什么这个 tar 命令在 ssh 调用中作为字符串传递时会失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31061043/