Unzip subdirectory contents of zip file to /tmp?

11,664

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!

Share:
11,664

Related videos on Youtube

andrew.46
Author by

andrew.46

The Tao is close, but you look far away. Life is simple yet you look for problems...

Updated on September 18, 2022

Comments

  • andrew.46
    andrew.46 over 1 year

    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?

  • Anwar
    Anwar over 7 years
    what does -j do?
  • Terrance
    Terrance over 7 years
    @Anwar Added from the manpage what -j does.
  • Anwar
    Anwar over 7 years
    OP wanted to extract the contents of samples, there might be some directory they don't want to lose.
  • Terrance
    Terrance over 7 years
    @Anwar With folder names would keep the directory structure.