-1

I use this command to extract a zip file containing a backup of my document root:

unzip /var/www/html/html-2018-01-08-02\:52\:11.zip -d /var/www/html/

This extracts all data inside the document root, but there's a problem, the current state is a duplicated document root:

/var/www/html/var/www/html/DATA

Of course I can move the data back with mv and then delete the duplicated document root with cd /var/www/html && rm -rf /var/www/html, but the most minimal solution would be to achieve that directly form unzip.

I aspire that the duplication won't happen in the first place.


How to unzip indoes only of a particular tier/level of a zip file, with unzip?

For example, my zip includes:

  • First tier: /var.
  • Second tier: /var/www.
  • Third tier: /var/www/html/.

I want to extract only the inodes of the forth tier (tier 3, in zero-based index, of course).

The end state should be:

/var/www/html/DATA

closed as unclear what you're asking by muru, maulinglawns, telcoM, Rui F Ribeiro, G-Man Jan 29 '18 at 3:23

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

2

You can limit unzip to the files you want to extract, by path:

With wildcards:

unzip foo.zip '*/*/*/*'

With literal syntax:

unzip foo.zip 'var/www/html/*'

For example:

$ zipinfo ../1.zip 
Archive:  ../1.zip
Zip file size: 1134 bytes, number of entries: 8
drwxrwxr-x  3.0 unx        0 bx stor 18-Jan-28 13:53 1/
drwxrwxr-x  3.0 unx        0 bx stor 18-Jan-28 13:53 1/2/
drwxrwxr-x  3.0 unx        0 bx stor 18-Jan-28 13:53 1/2/3/
drwxrwxr-x  3.0 unx        0 bx stor 18-Jan-28 13:53 1/2/3/4/
-rw-rw-r--  3.0 unx        0 bx stor 18-Jan-28 13:53 1/2/3/4/d
-rw-rw-r--  3.0 unx        0 bx stor 18-Jan-28 13:53 1/2/3/c
-rw-rw-r--  3.0 unx        0 bx stor 18-Jan-28 13:53 1/2/b
-rw-rw-r--  3.0 unx        0 bx stor 18-Jan-28 13:53 1/a
8 files, 0 bytes uncompressed, 0 bytes compressed:  0.0%
$  unzip ../1.zip '*/*/*/*'
Archive:  ../1.zip
   creating: 1/2/3/
   creating: 1/2/3/4/
 extracting: 1/2/3/4/d               
 extracting: 1/2/3/c
  • In the end I used unzip ${drt}/all_zipped* && mv ${drt}/${drt}/* ${drt}/ && rm -rf ${drt}/${drt}/ while ${drt} is my document root. – pntshere Jan 28 '18 at 10:23

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