Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 6 down vote accepted

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 -@ ...
share|improve this answer
    
Thanks, that is indeed the solution. – Gadolin Oct 18 '10 at 21:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .