我有以下目录结构:
/Data
- file 1
- file 2
/Folder1
- file 3
- file 4
/Folder2
- file 5
- file 6
/Folder3
- file 7
- file 8
在 Linux 中,我想在每个目录中压缩文件(不包括文件夹),并在每个文件夹中创建一个7z(或zip)存档,结果如下:
/Data
Data.7z (Note: this should contain only file1 & 2, not any sub directories)
/Folder1
Folder1.7z (this should contain only file3 & 4, not any sub directories)
/Folder2
Folder2.7z (this should contain only file5 & 6, no Folder3)
/Folder3
Folder3.7z (should contain only file7 & 8)
以下脚本适用于第一个目录,但不适用于子目录:for i in */ ; do base=$(basename “$i”) ; cd $base ; 7za a -t7z -r $base * ; .. ; cd .. ; done;
我怎样才能做到这一点?谢谢。