Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How does one extract a specific folder from a zipped archive to a given directory?

I tried using

unzip "/path/to/archive.zip" "in/archive/folder/" -d "/path/to/unzip/to"

but that only creates the folder on the path I want it to unzip to and does nothing else.

share|improve this question

2 Answers 2

up vote 19 down vote accepted

Try:

unzip "/path/to/archive.zip" "in/archive/folder/\*" -d "/path/to/unzip/to"
share|improve this answer
4  
did this? I get caution: filename not matched: foldername/\* when I run unzip $repozip "$2-master/\*" -d /srv/www/magento/ where $2 is the folder name in the zip I want to pull all the files and folders out of –  jeremy.bass Oct 18 '13 at 2:43
1  
I just tried this and it didn't work for me either! –  slm Nov 7 '13 at 20:57
7  
Worked without \, just "path/*". –  Alex Oct 28 '14 at 21:24
1  
Is there a way to extract contents of "in/archive/folder/*" that does not preserve path "in/archive/folder/"? I end up using mv afterwards to get files where I needed them. –  jerrygarciuh Nov 12 '14 at 20:29
3  
Use -j for that. –  Mark Adler Nov 12 '14 at 20:55
unzip <target-zip-file> '<folder-to-extract/*>' -d <destination-path> 

works fine on EL 6

share|improve this answer
    
what is this EL 6? –  Zelda Feb 14 '14 at 18:11
1  
Enterprise Linux 6 (RHEL6) - Red Hat. –  slm Feb 14 '14 at 18:15
    
This works too; its basically the same answer as Mark Adler's, but in a slightly different way. –  Enkouyami Feb 19 '14 at 19:44
    
@Enkouyami Minus differences in quoting, it looks like exactly the same thing. –  Camilo Martin Jan 25 at 6:53
1  
@Enkouyami Because backslash in double quotes escapes a character (supposedly the asterisk is being escaped, but I guess it's a typo), while in single quotes the backslash is not interpreted. If one wants a literal backslash, "\\" would be used (else you'd always have to remember which characters are special escapes). So it's a quoting difference if the author meant "quoting the glob character" (unnecessary). Either way a single backslash like that is a typo. –  Camilo Martin Mar 3 at 17:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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