简体   繁体   English

Shell:复制某些类型的文件以保持目录结构

[英]Shell: Copy Certain Types of Files Keeping Directory Structure

Say I have a folder following the structure below: 说我有以下结构的文件夹:

$ ls /tmp/level1
level2_folder1    level2_folder2
$ ls /tmp/level1/level2_folder1
input output script.py ...
$ ls /tmp/level1/level2_folder2
input output script.py ...

I want to copy all the Python scripts ONLY to somewhere else but keeping the existing structure. 我只想将所有Python脚本复制到其他地方,但要保留现有结构。 Let's say I want to copy the level1 folder to home/ so it should looks like this: 假设我想将level1文件夹复制到home /,所以它应该像这样:

$ ls /home/level1
level2_folder1    level2_folder2
$ ls /home/level1/level2_folder1
script.py 
$ ls /home/level1/level2_folder2
script.py

How could I do that? 我该怎么办?

rsync -avz --include "*/" --include "*.py" --exclude "*" /tmp/level1 /home
cd /tmp && find level1 -name '*.py' -print0 | cpio -pd0 /home

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM