Quick Tip #4: How to Unpack ANY Archive Under Linux

Print this articlePrint this article

To extract files from literally ANY existing archive, except really rare or closed sourced, there is a wonderful utility called 7-Zip. Unfortunately, it is only available for Microsoft Windows based systems.

Luckily, there is a command line port called ‘p7zip’, giving you all features of 7 Zip under Linux shell.

To begin working with it, we should first install it. Easiest way to do it, is by using package manager default to your system. In our case, it is APT which is default for Ubuntu.

So, we execute this command:

sudo apt-get install p7zip

NOTE: It WILL ask you for your (administrative) password, so be ready to type it in.

After it is installed, you can easily work with it, executing ‘7za’ command.

How to extract files using p7zip

To extract files from *.7z, *.cab, *.rpm, *.deb, *.zip and many other archives, use single command:

7za e archive.[ARCHIVE extension]

For example:
7za e “Full Wikileaks Archive.zip”
7za e “wikileaks cablegate-201103061731.7z”
7za e Data1.cab

How to extract file to specific path using p7zip

To extract files to specific path, issue the following command:

7za e -o/somepath MySQL-5.1.rpm – will extract contents of MySQL-5.1.rpm to /somepath

How to extract files with full paths using p7zip

To extract files recreating full paths, execute the following command:

7za x Apache-2.deb – will extract all files with full paths from Apache-2.deb

How to extract a single file using p7zip

To extract a single file from 7-zip supported archive, issue this command:

7za e Games.zip descr.lst – will extract descr.lst from Games.zip

BUT, if archives are compressed using two programs or more, it will only see content of the topmost archive. For example, if we have archive named GeoIP.tar.gz with README archived inside, issuing the following command:

7za e GeoIP.tar.gz READMEwill NOT extract README file

Because it will see only topmost content, which, in our case is GeoIP-1.4.6.tar (sub-archive of gzipped GeoIP.tar.gzip). So, in order to extract a single file from such archive, we should first extract topmost file:

7za e GeoIP.tar.gz

This will leave us with GeoIP-1.4.6.tar, from which we can extract README file with:

7za e -r GeoIP-1.4.6.tar README

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <span>
  • Lines and paragraphs break automatically.
  • Each email address will be obfuscated in a human readable fashion or (if JavaScript is enabled) replaced with a spamproof clickable link.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • Each email address will be obfuscated in a human readable fashion or (if JavaScript is enabled) replaced with a spamproof clickable link.
Image CAPTCHA
Enter the characters shown in the image.