Reputation: 1252
Hi I have to unzip a file that could have a Directory and I want to exclude everything within that directory, I tried lot of options and looked here as well, but doesn't seem to find any good solution.
These are the contents of the zip file: Please note the depth of EXCLUDE folder is unknown, but we have to exclude everything
$unzip -l patch2.zip
Archive: patch2.zip
Length Date Time Name
--------- ---------- ----- ----
0 2013-10-29 17:42 EXCLUDE/
0 2013-10-29 17:24 EXCLUDE/inner/
0 2013-10-29 17:24 EXCLUDE/inner/inner1.txt
0 2013-10-29 15:45 EXCLUDE/file.txt
0 2013-10-29 15:44 patch.jar
0 2013-10-29 15:44 system.properties
--------- -------
0 6 files
I tried this command, which only extract the files within it, but not the folder and its contents:
$unzip -l patch2.zip -x EXCLUDE/*
Archive: patch2.zip
Length Date Time Name
--------- ---------- ----- ----
0 2013-10-29 17:42 EXCLUDE/
0 2013-10-29 17:24 EXCLUDE/inner/
0 2013-10-29 17:24 EXCLUDE/inner/inner1.txt
0 2013-10-29 15:44 patch.jar
0 2013-10-29 15:44 system.properties
--------- -------
0 5 files
Thanks for the help.
Upvotes: 20
Views: 26076
Reputation: 3791
@dogbane answer is right.
But I still add another [I hope] interresting option, as you are on linux:
mc
(aka: Midnight Commander)
Start it, and then : on the Right panel, navigate to where you want your files to end up, and on the Left panel, navigate "inside" the ZIP file, and at that first level select + copy the things you need (ie, select all, and unselect the EXCLUDE folder, for example)
mc
is VERY flexible and nice to use, especially to tar/untar/zip/move/delete/rename files... (on windows, an equivalent is TotalCommander, and I use its "synchronise" option very often to keep backups and origin in sync). It allow you to navigate archives as if they were uncompressed (trying to minimize the actual decompression to just the "navigating" part so you don't uncompress them twice).
Upvotes: 2
Reputation: 274758
You need to quote the exclude pattern so that it is passed to unzip
. Otherwise it will be expanded by the shell before being passed to unzip
.
Try:
unzip patch2.zip -x "EXCLUDE/*"
Upvotes: 33