linux - bash/scp 如何展开 "remote"glob 模式?

标签 linux bash exec glob

如果我执行(在 bash 中):

scp remote.machine:/var/log/sy* .

我在远程机器上得到了所有匹配/var/log/sy* 的文件。

syslog                                     100%   91KB  10.1KB/s   00:09    
syslog.1                                   100%  753KB  62.7KB/s   00:12    
syslog.2.gz                                100%   55KB   7.9KB/s   00:07    
syslog.3.gz                                100%   50KB   8.3KB/s   00:06   

这是如何工作的?

我的印象是在执行命令之前 shell 扩展了 glob 模式。

我的理解有误吗?

最佳答案

你的理解是正确的。但是:

您的本地 shell 无法展开 remote.machine:/var/log/sy* ,因为您没有这样的文件(可能;当前文件夹中的目录 remote.machine: 的子目录树 var/log/ 包含 sy* 文件的情况非常罕见。

因此您的 shell 将字符串提供给 scp未扩展,将其交给远程系统,远程系统解析并使用它。

关于linux - bash/scp 如何展开 "remote"glob 模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15678694/

相关文章:

php - artisan 迁移——种子错误

bash - 将带有后缀的 date() 添加到 sqlite3 查询中

bash - M4:如何从文件中删除脚本中的前导空格?

java - 在 Java 中执行命令而不重定向输出

c++ - Linux 上的 Chilitags 编译

c - Linux 上的线程局部变量访问速度有多快

python - 如何提交调用我的 python 脚本的 SGE 作业

bash - 使用纯 bash 计算变量中行数的更清晰方法?

python - Python 中的 importlib.reload() 和 exec()

multithreading - stdin、stdout 和 stderr 是共享的吗?