如何使用 rsync 迁移隐藏文件

yes*_*nth 0 command-line bash hidden-files rsync

我在目标服务器中使用以下命令:

rsync -ab myuser@sourcehost:/source_dir/* target_dir
Run Code Online (Sandbox Code Playgroud)

但这无法同步存在 source_dir 的隐藏文件,我需要使用任何东西,--include以便可以迁移隐藏文件。

但是这个包含选项不应该影响普通文件的迁移,因为我在我的脚本中使用了这个命令。

我该怎么办?

pLu*_*umo 5

问题不是rsync,而是外壳。

通常在 Ubuntu 中,dotglob是禁用的,这意味着.*扩展中排除以开头的文件。

你可以打开这个运行。

shopt -s dotglob
Run Code Online (Sandbox Code Playgroud)

然后你的命令应该工作(我认为你只是缺少-e ssh

dotglob使用后取消设置是明智的:

shopt -u dotglob
Run Code Online (Sandbox Code Playgroud)

或者,您可以简单地告诉rsync将文件夹内容复制到target_dir,其中包括隐藏文件:

rsync --ab -e ssh myuser@sourcehost:/source_dir/ target_dir
Run Code Online (Sandbox Code Playgroud)