Software & AppsOperating SystemLinux

How To Uncompress a *.7z File in Ubuntu and Preserve Directory Structure

Ubuntu 19

In this tutorial, we will guide you through the process of uncompressing a *.7z file in Ubuntu while preserving the directory structure. The *.7z file is an archive format that stands for 7-zip, you can compress multiple files into a single *.7z file.

Quick Answer

To uncompress a *.7z file in Ubuntu and preserve the directory structure, you can use the 7z command with the x option. Simply run 7z x <archive_name>.7z in the terminal, replacing <archive_name> with the actual name of your *.7z file. Alternatively, you can use the graphical interface of Nautilus or install the dtrx tool for a simpler extraction process.

Prerequisites

Before we begin, you need to have a Ubuntu system running on your computer. You also need to have administrative privileges to install necessary packages.

Installing the Necessary Package

The first step is to install the p7zip-full package. This package provides a command-line utility that can work with 7-Zip files. To install it, open a terminal window and type the following command:

sudo apt-get install p7zip-full

The sudo command allows you to run commands with administrative privileges, apt-get is the package handling utility in Ubuntu, and install is the command to install a new package.

Uncompressing a *.7z File

Once you have installed the p7zip-full package, you can use the 7z command to extract the files. If you want to extract the files with the full path, use the x option:

7z x <archive_name>.7z

Here, 7z is the command to run the 7-Zip utility, x is the option that tells the utility to preserve the directory structure, and <archive_name>.7z is the name of the *.7z file you want to uncompress. Replace <archive_name> with the actual name of your *.7z file.

Using a Graphical Interface

If you prefer a graphical interface, you can use Nautilus, the default file manager in Ubuntu. After installing p7zip-full, Nautilus should have an option to uncompress 7-Zip files. Simply right-click on the *.7z file and select the appropriate option.

Using the dtrx Tool

Another option is to use the dtrx tool, which stands for “Do The Right eXtraction”. This tool can handle various archive formats and is known for its simplicity. To install it, use the following command:

sudo apt-get install dtrx

Then, you can extract the archive by running:

dtrx <archive_name>.tar.XX

Replace <archive_name>.tar.XX with the name of your archive.

Using the p7zip Package

If you are using Ubuntu 17.04 or later, you can install the p7zip package instead of p7zip-full:

sudo apt install p7zip

To extract the files, use the -d command:

p7zip -d <archive_name>.7z

Be cautious with this method, as it will delete the input file by default. To preserve the input file, use the --keep option:

p7zip -d --keep <archive_name>.7z

Conclusion

In this article, we have discussed several methods to uncompress a *.7z file in Ubuntu while preserving the directory structure. We hope this guide has been helpful to you. If you have any questions or run into any issues, feel free to leave a comment below.

Can I uncompress a *.7z file in Ubuntu without installing any additional packages?

No, you need to install the p7zip-full package or an alternative tool like dtrx to uncompress a *.7z file in Ubuntu.

Can I uncompress a *.7z file in Ubuntu using the default file manager?

Yes, after installing p7zip-full, you can right-click on the *.7z file in Nautilus (the default file manager in Ubuntu) and select the appropriate option to uncompress it.

Will uncompressing a *.7z file using the `p7zip` package delete the original file?

Yes, by default, the p7zip package will delete the original file after uncompressing it. If you want to preserve the original file, use the --keep option.

Can I uncompress other archive formats using the `dtrx` tool?

Yes, the dtrx tool is capable of handling various archive formats, not just *.7z files. It is known for its simplicity and ease of use.

Is the `p7zip` package available in all versions of Ubuntu?

No, the p7zip package is available in Ubuntu 17.04 or later. If you are using an older version, you need to install the p7zip-full package.

Leave a Comment

Your email address will not be published. Required fields are marked *