128

Is there a way to extract files of tar.7z format using command line tools in Ubuntu?

  • yes it does @guntbert See the accepted answer "7z x PACKAGE.7z that should eXtract the packages with full path." How is that not command line? – Rinzwind Sep 05 '13 at 14:31
  • 2
    Sorry, but the question is not a duplicate. It asks for handling tar.7z files. Neither the previous question nor its answers cover this matter. Since the answers don't address this question fully, it was legitimate to pose the question here. – tohuwawohu Sep 05 '13 at 22:36
  • 1
    Yes I also agree, the point of the question is the extraction of the files with a tar.7z format. – pacodelumberg Sep 06 '13 at 17:12
  • 1
    @Rinzwind: Please give some time before marking any post as duplicate. Since you marked it first, all copied your action. This question is for extracting *.tar.7z not *.7z !! I guess you know the difference.. :) – Saurav Kumar Nov 30 '13 at 04:57
  • @SauravKumar they are exactly the same.Linux does not care about suffixes and an extraction is based on the 1st bytes of the file. It is an identical question. And I trust stephen, andrea, guntbert enough to PM me in chat when I mess up (I have lots of examples of that :D ) – Rinzwind Nov 30 '13 at 07:24
  • man tar mentions --format=v7, but unfortunately that's only for creating such files, not for extracting from them. – Camille Goudeseune Feb 27 '18 at 22:29
  • As a comment since new answers aren't allowed here: In 2024 I think it makes sense to use the official Linux version of 7-zip. See my answers here:https://askubuntu.com/a/1506737/800252. – Kvothe Mar 06 '24 at 17:38

3 Answers3

97

Yes - the package p7zip / p7zip-full provides a command-line application to zip/unzip 7z files. The command is simply 7z.

You can combine a 7z / tar call using a pipe:

7z x -so yourfile.tar.7z | tar xf - -C target_dir

where target_dir is a already-existing directory.

tohuwawohu
  • 7,352
  • 15
    Who ever publishes tar.7z (lzma compression) files should learn about tar.xz/txz (lzma2), since this compression if available for tar via J parameter (like tar -cJf; not to be confused: capital J is for xz, small j is for bzip2) when xz-tools package is installed. It's also the default format on kernel.org. – LiveWireBT Sep 05 '13 at 11:56
  • People may wish to use 7zip for the strong encryption and multi-volume support. – Aaron Jan 26 '15 at 20:47
  • 1
    I found the answer to my question of why people combine tarballs with 7z. Even though 7z can store trees of files, it apparently does not preserve Unix permissions and metadata, so tarball can be used to preserve that while using 7z. But then, I agree with @LiveWireBT, just use xz, gzip, or bzip2. – bambams Mar 30 '17 at 00:01
  • 1
    7z appears to be better for lots of smaller files. – Pavin Joseph Oct 06 '17 at 15:59
  • The cmd. line proposed here is not working $ sudo 7z x -so Prime95/p95v294b7.linux64 | tar xf - -C /usr/local/bin/ gave me Error: can't decompress folder tar: This does not look like a tar archive The working cmd. is $ sudo 7z x Prime95/p95v294b7.linux64.7z -o/usr/local/bin/ using the option from the bash cmd. 7z http://manpages.ubuntu.com/manpages/xenial/en/man1/7z.1.html – Antonio Feb 03 '18 at 19:41
  • 1
    @Antonio: The question (an thus, my answer) concerned tar.7z files, not simple .7z archives. If your file isn't a compressed tar archive, of course my cmd line example will fail, since the tar command doesn't find a tar archive to expand. – tohuwawohu Feb 04 '18 at 08:01
  • As a comment since new answers aren't allowed here: In 2024 I think it makes sense to use the official Linux version of 7-zip. See my answers here:https://askubuntu.com/a/1506737/800252. – Kvothe Mar 06 '24 at 17:37
78
  • Install p7zip-full if not already installed:

    sudo apt-get install p7zip-full
    
  • execute this command to extract .tar.7z file(go to directory where is your file, if myfile.tar.7z is your file name):

    7za x myfile.tar.7z
    tar -xvf myfile.tar
    
  • That's it. Actually first command extracts in .tar file then next command extracts it completely.

Saurav Kumar
  • 14,916
44

Make sure that 7zip is installed, if not, just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the command(s) below:

sudo apt-get install p7zip

To install the command line utility do:

sudo apt-get install p7zip-full

Once done you can do the following to extract:

7z e <file_name>.tar.7z

To extract with full paths:

7z x <file_name>.tar.7z

To specify a path to extract to:

7z x <file_name>.tar.7z -opath

7z does not allow spaces between -o and path.

Eliah Kagan
  • 117,780
Mitch
  • 107,631