Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 a.zip, b.zip, and c.zip. even I dont know the folders names are like a,b, c we have to this dynamically.

share|improve this question

1 Answer 1

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 at 4:36

Your Answer

 
discard

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.