拉链/焦油/?带有深度参数的文件

Gad*_*lin 6 linux compression zip tar

我想从目录中压缩文件,但只能压缩到给定的深度。在下面的示例中,我想包含深度为 3 的文件:

dir0/
 dir1/
     dir2 -> subdir1, subdir2
     dir3 ->
     file1
Run Code Online (Sandbox Code Playgroud)

如果我可以发出:

zip --depth 3 -r output dir0
Run Code Online (Sandbox Code Playgroud)

我会有以下输出:

dir0/dir1/file1
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?我应该使用 tar,还是在 Linux 中还有其他常用工具?

Ign*_*ams 7

使用findwith-maxdepth限制遍历深度,然后使用工具的选项从 stdin、xargs 或命令替换中获取文件名。

find ... -maxdepth 3 ... | zip -@ ...
Run Code Online (Sandbox Code Playgroud)