根据ssh我机器上的人的说法:
If command is specified, it is executed on the remote host instead
of a login shell.
Run Code Online (Sandbox Code Playgroud)
这意味着 ssh 传递的命令的 shell 扩展不会在远程端完成。因此我们需要“自包含”命令,它不依赖于外壳扩展。
ssh user@remote-machine "find /path/to/directory -type f -exec rm {} \;"
Run Code Online (Sandbox Code Playgroud)
在这里,查找要删除的文件的所有工作都完全由 完成find,无需 shell 的帮助。
一些类似的问题