7z is one of the many high compression archiving utilities available for linux, that supportts many archiving algorithms.
But 7z is not as widely used as tar, gzip or bzip2 in Linux or other UNIX like systems.
So when most beginners got a 7z archive, they may be thinking about how to extract 7z file in Linux properly. Well, the man page is not exactly very helpful. So I’m writing this tutorial, also covering how to crate one.
Install 7z extracting and creating tools in Linux
To extract 7z files, you’re going to need an proper tool to do that, if not installed already.
In Linux, the 7zip extracting or creating utility is provided by p7zip, so you’re going to need that.
TO Install p7zip in Ubuntu, Debian or any other Debian derevative, use
sudo apt-get install p7zip-full
Install p7zip in Fedora
sudo dnf install p7zip
Install in Arch Linux
sudo pacman -S p7zip
The 7z command can extract almost anything, like a deb or rpm package, ISO files, exe files, cab archives and more.
Extract 7z in Linux
Simply use the 7z command to extract the archives, use the e argument to extract everything inside that archive to a single folder, or use the x argument to extract with full path. Example below,
7z e sample_archive.7z
Using the x argument with 7z command will extract the content with their full path.
7z x sample_archive.7z
Extracting the 7z file to a specific folder
All the above commands will extract the contents to the current working folder(pwd). So if you want to extract the archive to a specific folder, you’ve to specify that with the -o argument.
7z x sample_archive.7z -o/path/to/output/folder
Carefully note that there is no space after the -o agrument, an imaginary folder path used above, don’t forget to modify it according to yours.
Another useful option is l, list contents of 7z file without exracting it.
7z l sample_archive.7z
Create 7z archives
A 7z archive could be created with the a argument with the 7z command. Example below,
7z a output_archive.7z /path/to/folders/ /path/to/files
7z a diagram_backup.7z /home/b00m/circuits/ 555_pwm2.gif 555_pwm.jpg
Note: It’s clearly stated that 7zip archives are not fit for backup purpose in Linux if you want to preserve owner/group and permission of the files.
In such cases, using tar is recommanded. Exmaple – Creating a tar.7z archive.
tar cf - /var/backup_folder/ | 7za a -si ~/my_backup.tar.7z
Restoring the archive,
7za x -so my_backup.tar.7z | tar xf -
Updating and editing a 7z archive
Use the l option to get and overview of the 7z archive without extracting it.
You can delete one or many files of the archive using the d option, example :-
7z d archive_name.7z files-to-delete /path/of/files/to/delete
Another real world example
7z d diagram_backup.7z 555_pwm2.gif ups_circuit/5v_UPS.png
Updating an archive: –
You can update an existing archive to add some extra files of folders. A typical example:-
7z u sample_archive.7z /path/to/new/files/to/include
A real world example:-
7z u diagram_backup.7z ../../__b00m/esp_doc/
As always, check the archive with 7z l to make sure the changes are applied properly.
Another thing you might want to do with 7z is integrity checking with the t option, to make sure that the 7z file is OK .
7z t /path/to/sample_archive.7z
So, that’s all about how to create and extract 7z Linux, and hope you enjoyed reading this tutorial !