0

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.

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

| 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 - Reinstate Monica Jul 19 '14 at 4:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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