Reputation: 7318
I'm in a directory and I have a zip containing files and directories. I need to unzip that file, into current directory, but preserving the file structure.
unzip myfile.zip will create a myfile directory in current directory which is not what I want.
unzip -j myfile.zip will kill all the file strucure, which is not what I want.
Upvotes: 36
Views: 87724
Reputation: 21
Dont select the folder while zipping. For example myfile/abc.txt and myfile/efg.txt so while zipping select the files (abc.txt,efg.txt) and zip dont select the myfile folder to zip. So that when you unzip the file, the parent dir for each file or folder will be the directory in which you unzip.
Upvotes: 2
Reputation: 5976
unzip myfile.zip
extracts files in the working directory by keeping path names from the zip file.
So if you get a subdirectory myfile
it means it is part of the relative path of compressed files. Check it by listing the zip content
unzip -l myfile.zip
So you can unzip the file from the directory above, or, from the target directory unzip with -d
option, where -d is the directory above
cd myfile
unzip myfile.zip -d ..
Upvotes: 40
Reputation: 543
The myfile directory was zipped into the zip file when it was created and looking at the unzip options there isn't a way to do this without adding additional steps.
If this entire process is under your control you should look at either creating the zip without using including the parent directory or you could use an alternative like tar (to create and extract) which allows you to extract content from the repo with greater precision.
Upvotes: 1