Tuesday, August 18, 2015

How to flatten a zip file directory structure

This is short but super useful. 

If you have a zip file with a directory structure but want all the files to be extracted in the same folder, use the 'junk paths' parameter (-j). It will extract all the files in the zip file to the current folder, completely disregarding the directory structure.

Example:

 unzip -l myrubygems.zip

  Length      Date    Time    Name
---------  ---------- -----   ----
    27136  2015-08-14 16:05   dist/cache/actionmailer-4.2.3.gem
   185344  2015-08-14 16:05   dist/cache/actionpack-4.2.3.gem
   144896  2015-08-14 16:05   dist/cache/actionview-4.2.3.gem
    18944  2015-08-14 16:05   dist/cache/activejob-4.2.3.gem
    45568  2015-08-14 16:05   dist/cache/activemodel-4.2.3.gem
   327680  2015-08-14 16:05   dist/cache/activerecord-4.2.3.gem
   329728  2015-08-14 16:03   dist/cache/activesupport-4.2.3.gem

 unzip -j myrubygems.zip 

  inflating: actionmailer-4.2.3.gem  
  inflating: actionpack-4.2.3.gem    
  inflating: actionview-4.2.3.gem    
  inflating: activejob-4.2.3.gem     
  inflating: activemodel-4.2.3.gem   
  inflating: activerecord-4.2.3.gem  
  inflating: activesupport-4.2.3.gem  

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.