LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-09-2010, 04:33 PM   #1
SirTristan
Member
 
Registered: Feb 2006
Distribution: GNU/Linux
Posts: 54

Rep: Reputation: 15
zip -x for a directory - Subfolder contents not being excluded recursively?


I am attempting to use the zip command with the '-x' option to exclude a folder e.g. 'zip upload.zip public_html -x public_html/jquery/*'. However, parts of this folder are still being added to the archive. I made a shell script (saved as 'compress.sh' and ran as '. compress.sh') to do the archiving so I could test adding nested wildards for multiple subfolder levels.
Code:
#!/bin/bash
rm -f upload.zip
zip -r upload.zip public_html \
 -x public_html/jquery \
 -x public_html/jquery/ \
 -x public_html/jquery/* \
 -x public_html/jquery/*/* \
 -x public_html/jquery/*/*/* \
 -x public_html/jquery/*/*/*/* \
 -x public_html/jquery/*/*/*/*/* \
 -x public_html/jquery/*/*/*/*/*/* \
 -x public_html/jquery/*/*/*/*/*/*/*
Each new line I added here that has the nested wildcards made the archive file size a bit smaller. Adding more /*'s than this didn't affect the file size. Even after all this though, there were still a couple megabytes of files and folders from the 'jquery' directory that were added to the archive.

Here's some examples of files and folders that were created after I unzipped the archive:
public_html/jquery/js/tablesorter/addons/pager/icons [folder]
public_html/jquery/js/tablesorter/addons/pager/.svn/entries [file]
public_html/jquery/js/tablesorter/build/.svn/text-base/js.jar.svn-base [file]

Why is it that despite all the -x lines, the files and folders like these were still being added to the archive? How can I simply recursively exclude the entire public_html/jquery folder from the archive?
 
Old 12-09-2010, 05:55 PM   #2
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850
Hello SirTristan,

first thing I saw in your code were the ".svg" directories. You cannot match a dotfile with an asterisk! What I mean:
Code:
* does not match .svg
but
Code:
.* matches .svg
another point is that the -x option matches only files, not pathes or directories.

Markus
 
Old 12-09-2010, 08:35 PM   #3
SirTristan
Member
 
Registered: Feb 2006
Distribution: GNU/Linux
Posts: 54

Original Poster
Rep: Reputation: 15
Thank you I think I figured it out though. You can match directories with the -x option, but you need to put quotes around the path. Not sure why that is, but this code seems to work:
Code:
#!/bin/bash
rm -f upload.zip
zip -r upload.zip public_html \
 -x "public_html/jquery/*"
After creating this archive and unzipping it, the jquery folder is omitted entirely.

Anyone know what the significance of the quotes is? Does it have something to do with the way the wildcard is treated?
 
Old 12-10-2010, 01:17 AM   #4
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850
I don't think that's the point since
Code:
  -x "public_html/jquery/*/*/*"
will not exclude the path if the third asterisk should match ".svg".
The name "jquery" does not have a dot in front.

Markus
 
Old 12-10-2010, 04:52 AM   #5
SirTristan
Member
 
Registered: Feb 2006
Distribution: GNU/Linux
Posts: 54

Original Poster
Rep: Reputation: 15
But -x "public_html/jquery/*" excludes the whole folder, so that doesn't really matter to me. I was only using the nested wildcards because the first one wasn't working. The quotes change this.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
BASH: Listing contents of *.zip file into an array cade Programming 4 05-19-2010 05:13 PM
Listing Zip file contents prasanta_sadhukhan Linux - General 1 10-20-2009 08:43 AM
Recursively move files one directory up FLX Linux - Newbie 8 10-06-2009 02:41 PM
Browsing a directory recursively charlitos Linux - Newbie 4 02-16-2009 05:22 PM
list contents of directory without listing contents baddah Linux - Newbie 2 06-12-2006 05:02 AM


All times are GMT -5. The time now is 02:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration