4

As part of a scripted software installation on Xenial Xerus I have a zipped archive called 'test.zip' that contains, among other files, some files in a sub-directory called samples:

andrew@athens:~/Desktop$ unzip -l test.zip 
Archive:  test.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2016-09-15 13:29   materials/
       66  2014-11-16 18:22   materials/preferences.kcfgc
    21554  2014-11-16 18:22   materials/mainwindow.cpp
      166  2016-09-15 13:29   materials/.zip
      164  2014-11-16 18:22   materials/Messages.sh
        0  2016-09-15 13:28   samples/
    35147  2014-11-16 18:22   samples/LICENCE
      631  2014-11-16 18:22   samples/README.md
     2344  2014-11-16 18:22   samples/main.cpp
---------                     -------
    60072                     9 files
andrew@athens:~/Desktop$ 

Using Xenial Xerus's commandline unzip utility how do I extract the contents only of samples, decompressing them to /tmp?

9

The command would be to extract with folder names (default behavior):

unzip test.zip samples/* -d /tmp

without folder names (extracting files only contained in samples folder):

unzip -j test.zip samples/* -d /tmp

From man unzip:

   -j     junk paths.  The archive's directory structure is not recreated;
          all files are deposited in the extraction directory (by default,
          the current one).

Hope this helps!

4
  • 1
    what does -j do?
    – Anwar
    Sep 15 '16 at 4:42
  • @Anwar Added from the manpage what -j does.
    – Terrance
    Sep 15 '16 at 4:44
  • 1
    OP wanted to extract the contents of samples, there might be some directory they don't want to lose.
    – Anwar
    Sep 15 '16 at 4:48
  • @Anwar With folder names would keep the directory structure.
    – Terrance
    Sep 15 '16 at 4:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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