This is very close to the SO How to extract only a specific folder from a zipped archive to a given directory? I need something close but I always get the folder with the contents, not it's contents only This is what was suggested:

 #note $2 is passed in and would be == "magefoler"
 unzip /srv/file.zip "$2-master/*" -d /srv/www/mage/

What I need to do it to take a zip that has this structure in it

 |-magefoler-master/app/*tons of files
 |-magefoler-master/skin/*tons of files

and I need to move it to another folder but, I can't move the magefoler, I only want the app and skin folders. This doesn't mean that it'll always be those two folders, just that any child content, files or folders, in the magefoler is what I need to get out. What is trying to be avoided is to export all to a folder and then just move it from there.

The end result I'm looking for is from the zip file I output to the /mage folder like this:

     |--/mage/app/*tons of files
     |--/mage/skin/*tons of files

Can you not just unzip to here:

$ unzip /srv/file.zip "$2-master/*" -d /srv/www/

And then move/rename the folder magefoler-master to mage:

$ mv /srv/www/magefoler-master /srv/www/mage


In researching this exact problem in the past I was only able to find 2 additional methods to doing something like this without having to resort to using the mv.

  1. Using FUSE as Gilles suggests here: How can I force unzip / zip not to create a subdirectory when I extract it?
  2. Using the tool zipnote to move the files within the zip archive, prior to extracting them out.
| improve this answer | |
  • well no mage is a folder with things in it, and that approach of unzip then move contents out is what I'm trying to avoid. It's an extra I/O step and takes time that is sorely needed to be saved. The deal is I have about 30 of these and it's on a VM to a shared folder so it's slow so trying to skip the just dump and move contents is the goal – jeremy.bass Oct 18 '13 at 4:27
  • @jeremyBass_DC - I'm not sure what you're saying here. Moving a folder only requires one change, the inode that represents the folder has to just have its name changed, nothing more, no files need to actually move in this operation. – slm Oct 18 '13 at 4:30
  • even thou there is files and folders (many with the same names) in the mage folder, it will not file by file move the whole thing? seems like there would be a lot of I/O here.. ? – jeremy.bass Oct 18 '13 at 4:33
  • @jeremyBass_DC - no the files in the folder don't need to move with this operation. As long as the folder remains on the same physical disk then it's literally no overhead to perform this type of move. It's really a rename more than a move. – slm Oct 18 '13 at 4:34
  • well I guess I'll give that a go, seems odd that I can't just get the contents of a folder. – jeremy.bass Oct 18 '13 at 4:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.