Let's say I have a directory that contains subdirectories that I would like to zip in such a way that each subdirectory has its own zip file. Is there a way to do this with a script? I know I could do this manually but I would rather be able to just run the script
What I have so far:
ls -l $WORK/$SUBDIR > ~/listing
list="cat ~/listing | wc -l"
for d in $list; do
zip -r $d.zip $WORK/$SUBDIR/$d
Something's obviously wrong with this though as it doesn't do what I want it to do
I just slapped something together, but I'm not 100% sure it's exactly what you're after.
From your snippet, it looks like you want to hard-code the working directory, then at runtime you want to manually enter the name of a subdirectory to zip, correct? Is that actually how you want it? If so...ignore the following!
This--as it stands right now--has nothing hard-coded, meaning it can be run in any directory, and it automatically finds all of its subdirectories, and zips each one as its own subdirectory-named zip file in its own subdirectory. Obviously, this can be tweaked as far as location of the zipped files, whether or not you enter a directory/subdirectory name, and so on:
for SUBDIR in `ls -d1 */`
do ZIPFILE=`basename $SUBDIR`
zip -r $SUBDIR$ZIPFILE.zip $SUBDIR
Any questions about what's doing what, just ask.