假设我有一个遵循以下结构的文件夹:
$ 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 ...
我想将所有 Python脚本 复制到其他地方,但保留现有结构。让我们说我想将level1文件夹复制到home /所以它应该是这样的:
$ ls /home/level1
level2_folder1 level2_folder2
$ ls /home/level1/level2_folder1
script.py
$ ls /home/level1/level2_folder2
script.py
我怎么能这样做?
答案 0 :(得分:5)
rsync -avz --include "*/" --include "*.py" --exclude "*" /tmp/level1 /home
答案 1 :(得分:1)
cd /tmp && find level1 -name '*.py' -print0 | cpio -pd0 /home