{"id":11677,"date":"2019-03-15T21:36:41","date_gmt":"2019-03-15T21:36:41","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=11677"},"modified":"2019-03-15T21:36:41","modified_gmt":"2019-03-15T21:36:41","slug":"10-7zip-file-archive-command-examples-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/15\/10-7zip-file-archive-command-examples-in-linux\/","title":{"rendered":"10 7zip (File Archive) Command Examples in Linux"},"content":{"rendered":"<p><strong>7-Zip<\/strong>\u00a0is a free open source, cross-platform, powerful, and fully-featured file archiver with a high compression ratio, for\u00a0<strong>Windows<\/strong>. It has a powerful command line version that has been ported to\u00a0<strong>Linux\/POSIX<\/strong>\u00a0systems.<\/p>\n<p>It has a high compression ratio in\u00a0<strong>7z<\/strong>\u00a0format with\u00a0<strong>LZMA<\/strong>\u00a0and\u00a0<strong>LZMA2<\/strong>\u00a0compression, supports many other archive formats such as XZ, BZIP2, GZIP, TAR, ZIP and WIM for both packing and unpacking; AR, RAR, MBR, EXT, NTFS, FAT, GPT, HFS, ISO, RPM, LZMA, UEFI, Z, and many others for extracting only.<\/p>\n<p>It provides strong\u00a0<strong>AES-256<\/strong>\u00a0encryption in 7z and ZIP formats, offers a compression ratio that of\u00a0<strong>2-10 %<\/strong>\u00a0for ZIP and GZIP formats (much better than those offered by PKZip and WinZip). It also comes with self-extracting capability for 7z format and it\u2019s localized in up-to 87 languages.<\/p>\n<h3>How to Install 7zip in Linux<\/h3>\n<p>The port of\u00a0<strong>7zip<\/strong>\u00a0on Linux systems is called\u00a0<strong>p7zip<\/strong>, this package comes pre-installed on many mainstream Linux distributions. You need to install the\u00a0<strong>p7zip-full<\/strong>\u00a0package to get the 7z, 7za, and 7zr CLI utilities on your system, as follows.<\/p>\n<h4>Install 7zip on Debian, Ubuntu or Linux Mint<\/h4>\n<p>Debian-based Linux distributions comes with three software packages related to\u00a0<strong>7zip<\/strong>\u00a0and they are\u00a0<strong>p7zip<\/strong>,\u00a0<strong>p7zip-full<\/strong>\u00a0and\u00a0<strong>p7zip-rar<\/strong>. It is suggested to install\u00a0<strong>p7zip-full<\/strong>\u00a0package, which supports many archive formats.<\/p>\n<pre>$ sudo apt-get install p7zip-full\r\n<\/pre>\n<h4>Install 7zip on Fedora or CentOS\/RHEL<\/h4>\n<p>Red Hat-based Linux distributions comes with two packages related to\u00a0<strong>7zip<\/strong>\u00a0and they are\u00a0<strong>p7zip<\/strong>\u00a0and\u00a0<strong>p7zip-plugins<\/strong>. It is suggested to install both packages.<\/p>\n<p>To install these two packages, you need to enable EPEL repository on CentOS\/RHEL distributions. On Fedora, no need to setup additional repository.<\/p>\n<pre>$ sudo yum install p7zip p7zip-plugins\r\n<\/pre>\n<p>Once the\u00a0<strong>7zip<\/strong>\u00a0package installed, you can move further to learn some useful 7zip command examples to pack or unpack various types of archives in the following section.<\/p>\n<h3>Learn 7zip Command Examples in Linux<\/h3>\n<p><strong>1.<\/strong>\u00a0To create an\u00a0<code>.7z<\/code>\u00a0archive file, use\u00a0<code>\"a\"<\/code>\u00a0option. The supported archive formats for creation are 7z, XZ, GZIP, TAR, ZIP and BZIP2. If the given archive file exists already, it will \u201cadd\u201d the files to an existing archive, instead of overwriting it.<\/p>\n<pre>$ 7z a <strong>hyper.7z<\/strong> hyper_1.4.2_i386.deb\r\n<\/pre>\n<div id=\"attachment_29605\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/Create-7z-Archive-File-in-Linux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-29605\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/Create-7z-Archive-File-in-Linux.png\" alt=\"Create 7z Archive File in Linux\" width=\"762\" height=\"291\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Create 7z Archive File in Linux<\/p>\n<\/div>\n<p><strong>2.<\/strong>\u00a0To extract an\u00a0<code>.7z<\/code>\u00a0archive file, use\u00a0<code>\"e\"<\/code>\u00a0option, which will extract the archive in the present working directory.<\/p>\n<pre>$ 7z e <strong>hyper.7z<\/strong>\r\n<\/pre>\n<div id=\"attachment_29606\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/Extract-7z-Archive-File-in-Linux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-29606\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/Extract-7z-Archive-File-in-Linux.png\" sizes=\"auto, (max-width: 770px) 100vw, 770px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/Extract-7z-Archive-File-in-Linux.png 770w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/Extract-7z-Archive-File-in-Linux-768x351.png 768w\" alt=\"Extract 7z Archive File in Linux\" width=\"770\" height=\"352\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Extract 7z Archive File in Linux<\/p>\n<\/div>\n<p><strong>3.<\/strong>\u00a0To select an archive format, use\u00a0<code>-t<\/code>\u00a0(format name) option, which will allows you to select the archive format such as zip, gzip, bzip2 or tar (the default is 7z):<\/p>\n<pre>$ 7z a -tzip <strong>hyper.zip<\/strong> hyper_1.4.2_i386.deb\r\n<\/pre>\n<div id=\"attachment_29608\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/Create-7z-Zip-File-in-Linux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-29608\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/Create-7z-Zip-File-in-Linux.png\" sizes=\"auto, (max-width: 810px) 100vw, 810px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/Create-7z-Zip-File-in-Linux.png 810w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/Create-7z-Zip-File-in-Linux-768x259.png 768w\" alt=\"Create 7z Zip File in Linux\" width=\"810\" height=\"273\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Create 7z Zip File in Linux<\/p>\n<\/div>\n<p><strong>4.<\/strong>\u00a0To see a list of files in an archive, use\u00a0<code>\"l\"<\/code>\u00a0(list) function, which will displays the type of archive format, method used, files in the archive among other information as shown.<\/p>\n<pre>$ 7z l <strong>hyper.7z<\/strong>\r\n<\/pre>\n<div id=\"attachment_29609\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/List-7z-File-Information.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-29609\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/List-7z-File-Information.png\" sizes=\"auto, (max-width: 879px) 100vw, 879px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/List-7z-File-Information.png 879w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/List-7z-File-Information-768x385.png 768w\" alt=\"List 7z File Information\" width=\"879\" height=\"441\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">List 7z File Information<\/p>\n<\/div>\n<p><strong>5.<\/strong>\u00a0To test the integrity of an archive file, use\u00a0<code>\"t\"<\/code>\u00a0(test) function as shown.<\/p>\n<pre>$ 7z t <strong>hyper.7z<\/strong>\r\n<\/pre>\n<div id=\"attachment_29610\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/Check-7z-File-Integrity.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-29610\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/Check-7z-File-Integrity.png\" sizes=\"auto, (max-width: 843px) 100vw, 843px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/Check-7z-File-Integrity.png 843w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/Check-7z-File-Integrity-768x265.png 768w\" alt=\"Check 7z File Integrity\" width=\"843\" height=\"291\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Check 7z File Integrity<\/p>\n<\/div>\n<p><strong>6.<\/strong>\u00a0To backup a directory, you should use the\u00a0<strong>7za<\/strong>\u00a0utility which preserves owner\/group of a file, unlike 7z, the\u00a0<code>-si<\/code>option enables reading of files from stdin.<\/p>\n<pre>$ tar -cf - tecmint_files | 7za a -si tecmint_files.tar.7z\r\n<\/pre>\n<p><strong>7.<\/strong>\u00a0To restore a backup, use\u00a0<code>-so<\/code>\u00a0option, which will sends output to stdout.<\/p>\n<pre>$ 7za x -so tecmint_files.tar.7z | tar xf -\r\n<\/pre>\n<p><strong>8.<\/strong>\u00a0To set a compression level, use the\u00a0<code>-mx<\/code>\u00a0option as shown.<\/p>\n<pre>$ tar -cf - tecmint_files | 7za a -si -mx=9 tecmint_files.tar.7z\r\n<\/pre>\n<p><strong>9.<\/strong>\u00a0To update an existing archive file or remove file(s) from an archive file, use\u00a0<code>\"u\"<\/code>\u00a0and\u00a0<code>\"d\"<\/code>\u00a0options, respectively.<\/p>\n<pre>$ 7z u &lt;archive-filename&gt; &lt;list-of-files-to-update&gt;\r\n$ 7z d &lt;archive-filename&gt; &lt;list-of-files-to-delete&gt;\r\n<\/pre>\n<p><strong>10.<\/strong>\u00a0To set a password to an archive file, use\u00a0<code>-p<\/code>\u00a0{password_here} flag as shown.<\/p>\n<pre>$ 7za a -p{password_here} tecmint_secrets.tar.7z\r\n<\/pre>\n<p>For more information refer to the\u00a0<strong>7z<\/strong>\u00a0man page, or go to the 7zip Homepage:\u00a0<a href=\"https:\/\/www.7-zip.org\/\" target=\"_blank\" rel=\"nofollow noopener\">https:\/\/www.7-zip.org\/<\/a>.<\/p>\n<p>That\u2019s all for now! In this article, we have explained 10 7zip (File Archive) command examples in Linux. Use the feedback form below to ask any questions or share your thoughts with us.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/7zip-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>7-Zip\u00a0is a free open source, cross-platform, powerful, and fully-featured file archiver with a high compression ratio, for\u00a0Windows. It has a powerful command line version that has been ported to\u00a0Linux\/POSIX\u00a0systems. It has a high compression ratio in\u00a07z\u00a0format with\u00a0LZMA\u00a0and\u00a0LZMA2\u00a0compression, supports many other archive formats such as XZ, BZIP2, GZIP, TAR, ZIP and WIM for both packing and &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/15\/10-7zip-file-archive-command-examples-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;10 7zip (File Archive) Command Examples in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-11677","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11677","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=11677"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11677\/revisions"}],"predecessor-version":[{"id":11678,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11677\/revisions\/11678"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=11677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=11677"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=11677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}