Search code examples
bashshellunzip

How do I unzip a specific folder within a zipped file, and exclude some specific folder within it?


I have a zipped file:

main.zip

And I want to unzip only some folders present in the zipped folder while excluding the .git pack file.

The folder structure in main.zip is as follows: main.zip -> main_folder -> folder1, folder2... and I want to extract only folder2 from the zipped file, but this folder2 contains the .git folder with packed files, which I don't need.

So far I have tried :

unzip main.zip "main_folder/folder2/*" -d ~ path/to/some/directory

!(*.git) will exclude the files ending with .git, but how do I integrate this in the command above?


Solution

  • The exclude option works!

    We just need to provide a path to the files to be excluded!

    
    unzip main.zip "main_folder/folder2/*" -x "main_folder/folder2/*.git/*" -d path/to/some/directory