zip/tar/? files with depth parameter

6

1

I would like to zip files from a directory but only to a given depth. In the example below I would like to include files until a depth of 3:

dir0/
 dir1/
     dir2 -> subdir1, subdir2
     dir3 ->
     file1

If I could issue:

zip --depth 3 -r output dir0

I would have the following output:

dir0/dir1/file1

How can I achieve this? Should I use tar, or is there any other common tool in Linux?

Gadolin

Posted 2010-10-18T20:36:41.337

Reputation: 181

Answers

7

Use find with -maxdepth to limit the traversal depth, then use the tool's option to take filenames from stdin, or xargs or command substitution.

find ... -maxdepth 3 ... | zip -@ ...

Ignacio Vazquez-Abrams

Posted 2010-10-18T20:36:41.337

Reputation: 100 516