zip directory script

All Gurus once were Newbies
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Please stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions prefer the other forums within the support section.
Before you post please read how to get help

zip directory script

Postby actioncomics on Mon Dec 17, 2007 10:05 pm

since this is my first post on this board i thought i would start by saying..."Hello".

I am trying to zip a directory of files using the below code.

for x in *; do if [ -d "$x" ]; then zip -r "$x.zip" "$x"; fi; done

I have a directory with multiple sub directories. in those sub-directories i have multiples files. if i place this script in the top directory it will create multiple zip files using the sub-directory's name. problem is that in the zip file it creates a directory of the sub-directory, i would rather not have this directory and just have the files alone. Looking at the man pages for zip I noticed a -D option but can not get this to work. can anyone help? if all this does not make sense i will try to explain further. thanks.

ac
actioncomics
Level 1
Level 1
 
Posts: 2
Joined: Mon Dec 17, 2007 9:42 pm

Linux Mint is funded by ads and donations.
 

Re: zip directory script

Postby Husse on Tue Dec 18, 2007 7:30 am

Welcome to Mint actioncomics
that in the zip file it creates a directory of the sub-directory
This is the default behavior (also in Windows)
The -D option seems to be what you want and it should be put next to -r
If it does not work, well....
Image
Don't fix it if it ain't broken, don't break it if you can't fix it
Husse
Level 21
Level 21
 
Posts: 19703
Joined: Sun Feb 11, 2007 7:22 am
Location: Near Borås Sweden

Re: zip directory script

Postby actioncomics on Tue Dec 18, 2007 1:51 pm

i tried adding the "D" option after the "r" but with no luck. here are the options i tried.

-rD
-r -D
-r-D

I am still new to the terminal so i am not sure if i doing something wrong. If i can not add them to the script is there a way i can change (permanently) the way the zip function works?

ac
actioncomics
Level 1
Level 1
 
Posts: 2
Joined: Mon Dec 17, 2007 9:42 pm


Return to Newbie Questions

Who is online

Users browsing this forum: Google [Bot] and 37 guests