如何复制仅包含指定类型文件的目录?

Zen*_*Zen 1 command-line file-copy files

我有一个 git 目录,里面有很多 python 文件(和一些像 .git 这样的特殊文件)。
我只想将这些 python 文件复制到另一个目录,目录结构不变。

怎么做?

Cos*_*tas 5

您将收到destination_dir带有完整路径的文件/

find /path/git_directory -type f -iname "*.py" \
                         -exec cp --parents -t /path/destination_dir {} +
Run Code Online (Sandbox Code Playgroud)

其他解决方案是 rsync

rsync -Rr --prune-empty-dirs \
      --include="*.py" \
      --include="**/" \
      --exclude="*" \
      /path/git_directory /path/destination_dir
Run Code Online (Sandbox Code Playgroud)