How to extract a .7z compressed file in Linux

File owners choose several types of compression utilities as per their requirements. Sometimes they may use tar, unzip, bzip, and 7z, among other archiving and compression utilities.

And when you want to limit your space footprint, then 7z is an ideal compression mechanism, and that’s a reason one of the websites provides the VMware image in a 7z compressed file.

If you have downloaded the 7z compressed file or whenever you want to extract a 7z compressed file, you need to have p7zip and p7zip-full installed on your system.

Install the 7zip extractor tool in Linux

Therefore, the first and foremost step is to install p7zip-full on your Linux machine. If it is available, then you can ignore this step and follow the extraction method using the 7z command.

But how do I know p7zip utilities are installed on my system? It’s very simple: Just run the 7z or 7za, if it prints a “bash: 7z: command not found” error, then you need to run the following command according to your respective Linux distribution:

sudo apt install p7zip-full                                                                  // Ubuntu/Debian Based OS
sudo pacman -S p7zip                                                                        // Manjaro/Arch Based OS
sudo dnf install p7zip                                                                        // AlmaLinux/Fedora/RHEL Based OS

Extract 7z compressed file using command line

Once the installation is over, you are ready to extract the 7z compressed file on Linux. Therefore, go to the directory where the file is located and run the basic command to decompress the compressed file.

Extract 7z compressed file in the current directory

When you want to extract a file from a current directory without creating or preserving the original directory structure, then you can run the below command: 

7z x [FILE-NAME.7Z]
  • x command is used to extract the file
  • [FILE-NAME.7Z] provide a path or compressed file name

And this method can create a mess if the current directory has several files. So unless it is necessary, don’t run this command to extract files.

Extract 7z compressed files in a specific directory

The above command extracted the file into the current working directory, which I don’t want. Can you tell me what options I should use to extract the compressed files to a specific location?

Yes, you can use -o parameters to define the path location and don’t give a space after -o, else you will get the error message “Too short switch: -o“.

7z x [PATH/TO/ARCHIVE.7z] -o[PATH/to/OUTPUT]

For example, I have a compressed file at the /Downloads/TO location, but I want to extract it at /home/trendoceans/Desktop/VMwareImages

7z x ArchLinux_2022_VM.7z -o/home/trendoceans/Desktop/VMwareImages

If the extract point is not available, then 7zip will create a respective directory at the specified output location.

Once you entered the command wait for a while to complete the extraction because it may vary to file size and your system configuration.

Extract 7z compressed file in a specific directory
Extract 7z compressed file in a specific directory

Extract 7z compressed file to STDOUT

The 7z command allows you to read file content without extracting it to a physical location. This can be useful if you just want to read the content of the file and nothing else.

How to save the command output in Linux Terminal?

7z x -so [PATH/TO/ARCHIVE.7z] 
Extract 7z compressed file to STDOUT
Extract 7z compressed file to STDOUT

If you try to run this command on a non-textual compressed file, then it will print gibberish characters, which no one can understand. If you did this by mistake, remember to use Ctrl-Z to stop the reading process.

Interrupt or Suspend a Command Execution in Linux

Extract 7z compressed file using GUI

If you don’t want to use the command-line method to extract 7z compressed files, then you can use your regular file manager to extract the archive file in a pretty simple way. Most file managers are capable of extracting 7z compressed files like other compressed files.

I’m using the Nautilus file manager on my Debian machine, and I believe the steps will be similar to other file managers, except for a few more options that you will get in the Dolphin file manager.

To extract a 7z compressed file, go to the directory where the file is located and right-click on it. Choose extract here in the Nautilus file manager, and wait for a while to complete the extraction process.

Click on Extract here to extract 7z compressed file
Click on Extract Here to extract 7z compressed file

Wrap up

That’s all it takes to extract a.7z compressed file on Linux.

From this corresponding article, I hope you are able to install and use 7z to extract the compressed file. If this article worked for you, then please leave a comment about your experience.

Enjoy it!

Leave a Reply