UNIX:复制整个目录结构和特定文件类型

UNIX: copy entire directory structure and only specific file type

如何重新创建整个目录结构并仅复制扩展名为 .txt 的文件(如果存在)。我想复制目录或子目录,即使它是空的。

创建目录结构:

cd source-dir
find . -type d -exec mkdir target-dir/{} \;

您可以忽略.无法创建的消息。

然后,将txt个文件复制进去:

find . -type f -name '*.txt' -exec cp {} target-dir/{} \;

这是一行命令:)

rsync -vapEtogR --progress --stats --log-file="log_file_name.txt" --include '*/' --include '*.txt' --exclude '*' source_path/ destination_path/

使用rsync --help了解使用的选项。

cd source-dir
find . -type d -mindepth 1 -exec mkdir target-dir/{} \;

避免创建目录“.”和错误 "No such file or directory" 分别。