Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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:

     dir2 -> subdir1, subdir2
     dir3 ->

If I could issue:

zip --depth 3 -r output dir0

I would have the following output:


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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.