Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linux unzip excluding everything in the folder and underneath

Tags:

linux

unzip

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.

like image 420
Ravi Avatar asked Oct 29 '13 17:10

Ravi


People also ask

How do I exclude a folder from a zip file?

Exclude Multiple Files/Directories from Zip Archive You can define -x multiple times in a single zip command to exclude multiple files and directories from zip archive.

How do I unzip a file to a specific folder?

Do one of the following: To unzip a single file or folder, open the zipped folder, then drag the file or folder from the zipped folder to a new location. To unzip all the contents of the zipped folder, press and hold (or right-click) the folder, select Extract All, and then follow the instructions.

What is exclude folder?

If you trust a file, file type, folder, or a process that Windows Security has detected as malicious, you can stop Windows Security from alerting you or blocking the program by adding the file to the exclusions list. Caution: Only do this for files that you're confident are safe.


2 Answers

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/*"
like image 140
dogbane Avatar answered Oct 14 '22 20:10

dogbane


@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).

like image 44
Olivier Dulac Avatar answered Oct 14 '22 20:10

Olivier Dulac