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

How to Zip/Compress multiple folders individually in a directory using Unix?

for example in a X: directive I have a, b, c etc..folders I have to zip them as,, and even I dont know the folders names are like a,b, c we have to this dynamically.

share|improve this question

Assuming that you do want zip files,

cd /mydir/foo
find . -type d -d 1 -exec zip -r {} {} \;

This will create a zip file for every directory in /mydir/foo.

EDIT: what this commandline does (remember to never copy-paste a terminal command you don't understand, it's dangerous)

find . -type d -d 1 -exec xxx

will find all items inside . (in our case /mydir/foo), of type d for directory, then execute the command xxx

zip -r {} {}

is simply the zip command, (feel free to add the options you need, -r means recursive), using as its first (zip file) and second (source) arguments the special string {} that is fed by find with every match. \; is simply a terminator to tell find the -exec command is over, properly escaped to not be misinterpreted by the shell

share|improve this answer
Here is the updated command that will work on CentOS 6.5 find . -maxdepth 1 -type d -exec zip -r {} {} \; – James Wong Jul 19 '14 at 4:36

You must log in to answer this question.

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