{"id":12394,"date":"2019-03-26T22:25:35","date_gmt":"2019-03-26T22:25:35","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12394"},"modified":"2019-03-26T22:25:35","modified_gmt":"2019-03-26T22:25:35","slug":"how-to-compress-and-decompress-a-bz2-file-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/26\/how-to-compress-and-decompress-a-bz2-file-in-linux\/","title":{"rendered":"How to Compress and Decompress a .bz2 File in Linux"},"content":{"rendered":"<p>To compress a file(s), is to significantly decrease the size of the file(s) by encoding data in the file(s) using less bits, and it is normally a useful practice\u00a0<a href=\"https:\/\/www.tecmint.com\/rsync-local-remote-file-synchronization-commands\/\" target=\"_blank\" rel=\"noopener\">during backup and transfer of a file(s)<\/a>\u00a0over a network. On the other hand, decompressing a file(s) means restoring data in the file(s) to its original state.<\/p>\n<p><b>Suggested Read:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/18-tar-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">Learn Linux \u2018tar\u2019 Command with This 18 Examples<\/a><\/p>\n<p>There are several\u00a0<a href=\"https:\/\/www.tecmint.com\/command-line-archive-tools-for-linux\/\" target=\"_blank\" rel=\"noopener\">file compression and decompression tools<\/a>\u00a0available in Linux such as\u00a0<strong>gzip<\/strong>,\u00a0<strong>7-zip<\/strong>,\u00a0<strong>Lrzip<\/strong>,\u00a0<a href=\"https:\/\/www.tecmint.com\/peazip-linux-file-manager-and-file-archive-tool\/\" target=\"_blank\" rel=\"noopener\">PeaZip<\/a>and many more.<\/p>\n<p>In this tutorial, we will look at how to compress and decompress\u00a0<code>.bz2<\/code>\u00a0files using the bzip2 tool in Linux.<\/p>\n<p><strong>Bzip2<\/strong>\u00a0is a well known compression tool and it\u2019s available on most if not all the major Linux distributions, you can use the appropriate command for your distribution to install it.<\/p>\n<pre>$ sudo apt install bzip2     [On <strong>Debian\/Ubuntu<\/strong>] \r\n$ sudo yum install  bzip2    [On <strong>CentOS\/RHEL<\/strong>]\r\n$ sudo dnf install bzip2     [On <strong>Fedora 22+<\/strong>]<\/pre>\n<p>The conventional syntax of using\u00a0<strong>bzip2<\/strong>\u00a0is:<\/p>\n<pre>$ bzip2 option(s) filenames \r\n<\/pre>\n<h3>How to Use \u201cbzip2\u201d to Compress Files in Linux<\/h3>\n<p>You can compress a file as below, where the flag\u00a0<code>-z<\/code>\u00a0enables file compression:<\/p>\n<pre>$ bzip2 filename\r\nOR\r\n$ bzip2 -z filename\r\n<\/pre>\n<p>To compress a\u00a0<code>.tar<\/code>\u00a0file, use the command format:<\/p>\n<pre>$ bzip2 -z backup.tar\r\n<\/pre>\n<p><strong>Important<\/strong>: By default,\u00a0<strong>bzip2<\/strong>\u00a0deletes the input files during compression or decompression, to keep the input files, use the\u00a0<code>-k<\/code>\u00a0or\u00a0<code>--keep<\/code>\u00a0option.<\/p>\n<p>In addition, the\u00a0<code>-f<\/code>\u00a0or\u00a0<code>--force<\/code>\u00a0flag will force\u00a0<strong>bzip2<\/strong>\u00a0to overwrite an existing output file.<\/p>\n<pre>------ <strong>To keep input file<\/strong>  ------\r\n$ bzip2 -zk filename\r\n$ bzip2 -zk backup.tar\r\n<\/pre>\n<p>You can as well set the block size to\u00a0<strong>100k<\/strong>\u00a0upto<strong>\u00a0900k<\/strong>, using\u00a0<code>-1<\/code>\u00a0or\u00a0<code>--fast<\/code>\u00a0to\u00a0<code>-9<\/code>\u00a0or\u00a0<strong>\u2013best<\/strong>\u00a0as shown in the below examples:<\/p>\n<pre>$ bzip2 -k1  Etcher-linux-x64.AppImage\r\n$ ls -lh  Etcher-linux-x64.AppImage.bz2 \r\n$ bzip2 -k9  Etcher-linux-x64.AppImage \r\n$ bzip2 -kf9  Etcher-linux-x64.AppImage \r\n$ ls -lh Etcher-linux-x64.AppImage.bz2<\/pre>\n<p>The screenshot below shows how to use options to keep the input file, force\u00a0<strong>bzip2<\/strong>\u00a0to overwrite an output file and set the block size during compression.<\/p>\n<div id=\"attachment_23301\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/11\/Compress-Files-Using-bzip2-in-Linux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-23301\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/11\/Compress-Files-Using-bzip2-in-Linux.png\" sizes=\"auto, (max-width: 824px) 100vw, 824px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/11\/Compress-Files-Using-bzip2-in-Linux.png 824w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/11\/Compress-Files-Using-bzip2-in-Linux-768x250.png 768w\" alt=\"Compress Files Using bzip2 in Linux\" width=\"824\" height=\"268\" aria-describedby=\"caption-attachment-23301\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-23301\" class=\"wp-caption-text\">Compress Files Using bzip2 in Linux<\/p>\n<\/div>\n<h3>How to Use \u201cbzip2\u201d to Decompress Files in Linux<\/h3>\n<p>To decompress a\u00a0<code>.bz2<\/code>\u00a0file, make use of the\u00a0<code>-d<\/code>\u00a0or\u00a0<code>--decompress<\/code>\u00a0option like so:<\/p>\n<pre>$ bzip2 -d filename.bz2\r\n<\/pre>\n<p><strong>Note<\/strong>: The file must end with a\u00a0<code>.bz2<\/code>\u00a0extension for the command above to work.<\/p>\n<pre>$ bzip2 -vd Etcher-linux-x64.AppImage.bz2 \r\n$ bzip2 -vfd Etcher-linux-x64.AppImage.bz2 \r\n$ ls -l Etcher-linux-x64.AppImage \r\n<\/pre>\n<div id=\"attachment_23302\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/11\/Decompression-bzip2-File-in-Linux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-23302\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/11\/Decompression-bzip2-File-in-Linux.png\" sizes=\"auto, (max-width: 825px) 100vw, 825px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/11\/Decompression-bzip2-File-in-Linux.png 825w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/11\/Decompression-bzip2-File-in-Linux-768x161.png 768w\" alt=\"Decompress bzip2 File in Linux\" width=\"825\" height=\"173\" aria-describedby=\"caption-attachment-23302\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-23302\" class=\"wp-caption-text\">Decompress bzip2 File in Linux<\/p>\n<\/div>\n<p>To view the\u00a0<strong>bzip2<\/strong>\u00a0help page and\u00a0<strong>man page<\/strong>, type the command below:<\/p>\n<pre>$ bzip2  -h\r\n$ man bzip2\r\n<\/pre>\n<p>Lastly, with the simple elaborations above, I believe you are now capable of compressing and decompressing\u00a0<code>.bz2<\/code>\u00a0files using the\u00a0<strong>bzip2<\/strong>\u00a0tool in Linux. However, for any questions or feedback, reach us using the comment section below.<\/p>\n<p>Importantly, you may want to go over a few important\u00a0<a href=\"https:\/\/www.tecmint.com\/18-tar-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">Tar command examples<\/a>\u00a0in Linux so as to learn using the\u00a0<strong>tar<\/strong>\u00a0utility to\u00a0<a href=\"https:\/\/www.tecmint.com\/compress-files-and-finding-files-in-linux\/\" target=\"_blank\" rel=\"noopener\">create compressed archive files<\/a>.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/linux-compress-decompress-bz2-files-using-bzip2\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>To compress a file(s), is to significantly decrease the size of the file(s) by encoding data in the file(s) using less bits, and it is normally a useful practice\u00a0during backup and transfer of a file(s)\u00a0over a network. On the other hand, decompressing a file(s) means restoring data in the file(s) to its original state. Suggested &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/26\/how-to-compress-and-decompress-a-bz2-file-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Compress and Decompress a .bz2 File 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-12394","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\/12394","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=12394"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12394\/revisions"}],"predecessor-version":[{"id":12395,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12394\/revisions\/12395"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}