Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unzip in current directory while preserving file structure

Tags:

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.

like image 405
Robert Brax Avatar asked Jan 23 '17 10:01

Robert Brax


2 Answers

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 ..
like image 55
gile Avatar answered Sep 20 '22 16:09

gile


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.

like image 41
roshan nikam Avatar answered Sep 16 '22 16:09

roshan nikam