View Single Post
Old September 16th, 2013, 02:20 PM   #918 (permalink)
- Crazy peacock person -
Thread Author (OP)
MoodyBlues's Avatar
Join Date: Jan 2011
Location: /home/LosAngeles
Posts: 3,340
Device(s): Kindle Fire HD 8.9" (rooted), Motorola Atrix 2, Motorola Atrix 4G (retired), Motorola Bravo (retired
Carrier: AT&T

Thanks: 1,094
Thanked 1,564 Times in 969 Posts

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 $ $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`
Any questions about what's doing what, just ask.

MoodyBlues is offline  
Reply With Quote
The Following User Says Thank You to MoodyBlues For This Useful Post:
palmtree5 (September 16th, 2013)