Other Tutorials<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n\n\nInstall and Use 7zip on Ubuntu 18.04\/Ubuntu 20.04<\/h2>\n\n\n\nInstalling p7zip package<\/h3>\n\n\n\n
If the 7zip utility is not already installed in your system, run the command below to install it.<\/p>\n\n\n\n
apt install p7zip p7zip-rar p7zip-full -y<\/code><\/pre>\n\n\n\nIf you are running another Linux distribution like CentOS, Fedora or other RHEL based distros, run the command below to install 7zip;<\/p>\n\n\n\n
NB<\/strong>: Enable EPEL repository on CentOS\/RHEL distributions before you can run this command.<\/p>\n\n\n\nyum install p7zip p7zip-plugins -y<\/code><\/pre>\n\n\n\nThe 7zip utility provides three command line utilities namely, 7z, 7za <\/strong>and 7zr<\/strong>. The difference between the three utilities as outlined in their man pages is that;<\/p>\n\n\n\n\n- 7z<\/strong> uses plugins to handle archives.<\/li>\n\n\n\n
- 7za<\/strong> is a stand-alone executable. 7za handles less archive formats than 7z.<\/li>\n\n\n\n
- 7zr<\/strong> is a stand-alone executable. 7zr handles less archive formats than 7z. 7zr is a “light-version” of 7za that only handles 7z archives.<\/li>\n<\/ul>\n\n\n\n
If you would love to use 7zip with rar on Ubuntu and similar distributions, you need to install the p7zip-rar package.<\/p>\n\n\n\n
apt install p7zip-rar -y<\/code><\/pre>\n\n\n\nIn this tutorial, we will discuss the usage of one utility, 7z, since the functionality and usage is the same for all the three utilities.<\/p>\n\n\n\n
Once the installation is complete, you can verify by running the following command;<\/p>\n\n\n\n
whereis 7z 7za 7zr<\/code><\/pre>\n\n\n\n7z: \/usr\/bin\/7z \/usr\/share\/man\/man1\/7z.1.gz\n7za: \/usr\/bin\/7za \/usr\/share\/man\/man1\/7za.1.gz\n7zr: \/usr\/bin\/7zr \/usr\/share\/man\/man1\/7zr.1.gz<\/code><\/pre>\n\n\n\nCommand Line Syntax<\/h3>\n\n\n\n
Now that installation part is done, let’s have a look at command line syntax.<\/p>\n\n\n\n
The 7z command line syntax is:<\/p>\n\n\n\n
7z <command> [<switch>...] <base_archive_name> [<arguments>...] [<@listfiles...>]<\/code><\/pre>\n\n\n\n\n- <arguments><\/strong> can be specified as <switch> | <wildcard> | <filename> | <list_file><\/li>\n\n\n\n
- <switch><\/strong> can be specified in the format; <switch_symbol><switch_characters>[<option>]<\/li>\n\n\n\n
- <switch_symbol><\/strong> can be ‘\/’ | ‘-‘<\/li>\n\n\n\n
- <list_file><\/strong> is specified in the format; @{filename}<\/li>\n<\/ul>\n\n\n\n
NOTE<\/strong>: The expressions within the square brackets are optional while those within the curly braces have to be substituted by the user.<\/p>\n\n\n\nThe following is a brief description of the various commands and switches used with the 7z command;<\/p>\n\n\n\n
The <Commands><\/strong> can be any of the following;<\/p>\n\n\n\n\n- a: Add files to archive<\/li>\n\n\n\n
- b: Benchmark<\/li>\n\n\n\n
- d: Delete files from archive<\/li>\n\n\n\n
- e: Extract files from archive (without using directory names)<\/li>\n\n\n\n
- l: List contents of archive<\/li>\n\n\n\n
- t: Test integrity of archive<\/li>\n\n\n\n
- u: Update files to archive<\/li>\n\n\n\n
- x: eXtract files with full paths<\/li>\n<\/ul>\n\n\n\n
<Switches><\/strong><\/p>\n\n\n\n\n-ai[r[-|0]]{@listfile|!wildcard}<\/strong>: Include archives\n-ax[r[-|0]]{@listfile|!wildcard}<\/strong>: eXclude archives\n-bd<\/strong>: Disable percentage indicator\n-i[r[-|0]]{@listfile|!wildcard}<\/strong>: Include filenames\n-m{Parameters}<\/strong>: set compression Method\n-o{Directory}<\/strong>: set Output directory\n-p{Password}<\/strong>: set Password\n-r[-|0]<\/strong>: Recurse subdirectories\n-scs{UTF-8 | WIN | DOS}<\/strong>: set charset for list files\n-sfx[{name}]<\/strong>: Create SFX archive\n-si[{name}]<\/strong>: read data from stdin\n-slt<\/strong>: show technical information for l (List) command\n-so<\/strong>: write data to stdout\n-ssc[-]<\/strong>: set sensitive case mode\n-t{Type}<\/strong>: Set type of archive\n-u[-][p#][q#][r#][x#][y#][z#][!newArchiveName]<\/strong>: Update options\n-v{Size}[b|k|m|g]<\/strong>: Create volumes\n-w[{path}]<\/strong>: assign Work directory. Empty path means a temporary directory\n-x[r[-|0]]]{@listfile|!wildcard}<\/strong>: eXclude filenames\n-y<\/strong>: assume Yes on all queries\n-an<\/strong>: Disable parsing of archive_name\n<\/code><\/pre>\n\n\n\nFor a comprehensive list of switches, check the man pages of the 7z, 7zr, 7za or visit the command line switches<\/a>.<\/p>\n\n\n\nExample Command Usage<\/h3>\n\n\n\n
Now that we have learnt about some command options and the command line switches, let us see some practical usage of the 7z command. In this examples, we are going to use the following files and directories;<\/p>\n\n\n\n
ls<\/code><\/pre>\n\n\n\ntest-dir<\/strong> tfile4.txt tfile5.txt tfile6.txt<\/code><\/pre>\n\n\n\nls test-dir\/<\/code><\/pre>\n\n\n\ntfile1.txt tfile2.txt tfile3.txt<\/code><\/pre>\n\n\n\nCreate an Archive<\/h4>\n\n\n\n
To create an archive, run the 7z command in the format;<\/p>\n\n\n\n
7z a test-archive1.7z tfile4.txt tfile5.txt<\/code><\/pre>\n\n\n\n7z a archive.xz test-dir\/<\/code><\/pre>\n\n\n\nNote that, the supported archive types for creation are 7z, XZ, GZIP, TAR, ZIP and BZIP2. If the specified archive file already exists, it will “add” the files to the existing archive, instead of overwriting it.<\/p>\n\n\n\n
To unpack an archive to the current directory;<\/p>\n\n\n\n
7z e test-archive1.7z -y<\/code><\/pre>\n\n\n\nSupported archive types include 7z, XZ, GZIP, TAR, ZIP, BZIP2, LZMA2, CAB, ARJ, CPIO, RPM, ISO and DEB.<\/p>\n\n\n\n