{"id":6117,"date":"2018-08-09T17:17:53","date_gmt":"2018-08-09T13:17:53","guid":{"rendered":"https:\/\/www.howtoforge.com\/linux-bzcmp-bzdiff-bzmore-bzless-and-bzgrep-commands\/"},"modified":"2018-08-09T17:17:53","modified_gmt":"2018-08-09T13:17:53","slug":"linux-bzcmp-bzdiff-bzmore-bzless-and-bzgrep-commands-explained-with-examples","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/linux-bzcmp-bzdiff-bzmore-bzless-and-bzgrep-commands-explained-with-examples\/","title":{"rendered":"Linux bzcmp, bzdiff, bzmore, bzless, and bzgrep Commands Explained with Examples"},"content":{"rendered":"<p>While the bzip2 command line utility can be used to compress files, there are many other tools that let you perform basic tasks &#8211; like comparing such files &#8211; without the need to uncompress them. Here, in this tutorial, we will discuss the basics of bzcmp, bzdiff, bzmore, bzless, and bzgrep commands using some easy to understand examples.<\/p>\n<p>But before we do that, it&#8217;s worth mentioning that all examples in this article have been tested on an Ubuntu 18.04 LTS machine.<\/p>\n<h2 id=\"linux-bzcmp-bzdiff-bzmore-bzless-and-bzgrep-commands\">Linux bzcmp, bzdiff, bzmore, bzless, and bzgrep commands<\/h2>\n<p>We&#8217;ll discuss each of these commands using Q&amp;A-style of presentation.<\/p>\n<h3 id=\"q-how-bzcmp-and-bzdiff-commands-work\">Q1. How bzcmp and bzdiff commands work?<\/h3>\n<p>As their names suggest, these commands are used for comparing .bz2 files. Following is their syntax:<\/p>\n<p class=\"command\">bzcmp [ cmp_options ] file1 [ file2 ]bzdiff [ diff_options ] file1 [ file2 ]\n<p>And here&#8217;s what the man page says about them:<\/p>\n<pre> Bzcmp\u00a0 and\u00a0 bzdiff\u00a0 are\u00a0 used\u00a0 to invoke the cmp or the diff program on<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 bzip2 compressed files.\u00a0 All options specified are passed\u00a0 directly\u00a0 to<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 cmp\u00a0 or diff.\u00a0 If only 1 file is specified, then the files compared are<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 file1 and an uncompressed file1.bz2.\u00a0 If two files are specified,\u00a0 then<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 they\u00a0 are\u00a0 uncompressed\u00a0 if necessary and fed to cmp or diff.\u00a0 The exit<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 status from cmp or diff is preserved.<\/pre>\n<p>Here&#8217;s a basic example of bzcmp and bzdiff:<\/p>\n<p class=\"command\">bzcmp file1.bz2 file2.bz2<\/p>\n<p class=\"command\">bzdiff file1.bz2 file2.bz2<\/p>\n<p>And the following screenshot shows the output produced by these commands:<\/p>\n<p><a class=\"fancybox\" id=\"img-bzcmp-bzdiff\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/bzcmp-bzdiff.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-bzcmp-bzdiff-bzmore-bzless-and-bzgrep-commands-explained-with-examples.png\" alt=\"How bzcmp and bzdiff commands work\" width=\"500\" height=\"87\" title=\"\"><\/a><\/p>\n<p>While these commands do not explicitly offer any command line options, you can use the options from\u00a0<a href=\"https:\/\/www.howtoforge.com\/linux-cmp-command\/\" target=\"_blank\" rel=\"noopener\">cmp<\/a> and\u00a0<a href=\"https:\/\/www.howtoforge.com\/tutorial\/linux-diff-command-options\/\" target=\"_blank\" rel=\"noopener\">diff<\/a> commands (as these tools are internally invoked by bzcmp and bzdiff commands).<\/p>\n<h3 id=\"q-how-bzmore-and-bzless-commands-work\">Q2. How bzmore and bzless commands work?<\/h3>\n<p>Just like\u00a0<a href=\"https:\/\/www.howtoforge.com\/linux-more-command\/\" target=\"_blank\" rel=\"noopener\">more<\/a> and less, both bzmore and bzless are filters for CRT viewing, but for compressed bz2 files. To give you an even better idea, here&#8217;s an excerpt about bzmore from its man page:<\/p>\n<pre readability=\"11\"> Bzmore is a filter which allows examination of compressed or plain text<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 files one screenful at a time on a soft-copy terminal.\u00a0 bzmore works on<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 files\u00a0 compressed with bzip2 and also on uncompressed files.\u00a0 If a file<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 does not exist, bzmore looks for a file of the same name with the addi?<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 tion of a .bz2 suffix.<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Bzmore\u00a0 normally\u00a0 pauses after each screenful, printing --More-- at the<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 bottom of the screen.\u00a0 If the user then types a\u00a0 carriage\u00a0 return,\u00a0 one<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 more line is displayed.\u00a0 If the user hits a space, another screenful is<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 displayed.\u00a0 Other possibilities are enumerated later.<\/p><\/pre>\n<p>Of course, you can also use these commands to simply view a compressed file. Here&#8217;s an example:<\/p>\n<p><a class=\"fancybox\" id=\"img-bzmore-view\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/bzmore-view.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-bzcmp-bzdiff-bzmore-bzless-and-bzgrep-commands-explained-with-examples-1.png\" alt=\"How bzmore and bzless commands work\" width=\"500\" height=\"115\" title=\"\"><\/a><\/p>\n<h3 id=\"q-how-bzgrep-command-works\">Q3. How bzgrep command works?<\/h3>\n<p>As you&#8217;d have guessed by now, bzgrep also works on the lines of other bz series commands we&#8217;ve explained here. Specifically, it&#8217;s <a href=\"https:\/\/www.howtoforge.com\/tutorial\/linux-grep-command\/\" target=\"_blank\" rel=\"noopener\">grep<\/a>, but for compressed files. Following is an excerpt from the man page of this command:<\/p>\n<pre> Bzgrep is used to\u00a0 invoke\u00a0 the\u00a0 grep\u00a0 on\u00a0 bzip2-compressed\u00a0 files.\u00a0 All<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 options\u00a0 specified\u00a0 are\u00a0 passed directly to grep.\u00a0 If no file is speci?<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 fied, then the standard input is decompressed if necessary and\u00a0 fed\u00a0 to<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 grep.\u00a0\u00a0 Otherwise the given files are uncompressed if necessary and fed<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 to grep.<\/pre>\n<p>Here&#8217;s an example usage of bzgrep:<\/p>\n<p class=\"command\">bzgrep &#8220;menu&#8221; file1.bz2<\/p>\n<p>The following screenshot shows the output:<\/p>\n<p><a class=\"fancybox\" id=\"img-bzgrep\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/bzgrep.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-bzcmp-bzdiff-bzmore-bzless-and-bzgrep-commands-explained-with-examples-2.png\" alt=\"How bzgrep command works\" width=\"496\" height=\"37\" title=\"\"><\/a><\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>So if you are dealing with compressed files (.bz2), and want to perform basic operations like searching, comparing, and more, you can use these commands. We&#8217;ve discussed the basics here. For more information about these tools, head to their man pages (<a href=\"https:\/\/linux.die.net\/man\/1\/bzdiff\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>, <a href=\"https:\/\/linux.die.net\/man\/1\/bzmore\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>, and <a href=\"https:\/\/linux.die.net\/man\/1\/bzgrep\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>).<\/p>\n<div>\n<p><b>Share this page:<\/b><\/p>\n<p>\n<a href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.howtoforge.com%2Flinux-bzcmp-bzdiff-bzmore-bzless-and-bzgrep-commands%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-bzcmp-bzdiff-bzmore-bzless-and-bzgrep-commands-explained-with-examples-3.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-bzcmp-bzdiff-bzmore-bzless-and-bzgrep-commands%2F&amp;text=Linux+bzcmp%2C+bzdiff%2C+bzmore%2C+bzless%2C+and+bzgrep+Commands+Explained+with+Examples&amp;via=howtoforgecom&amp;related=howtoforgecom\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-bzcmp-bzdiff-bzmore-bzless-and-bzgrep-commands-explained-with-examples-4.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/howtoforgecom\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-bzcmp-bzdiff-bzmore-bzless-and-bzgrep-commands-explained-with-examples-5.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/plus.google.com\/share?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-bzcmp-bzdiff-bzmore-bzless-and-bzgrep-commands%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-bzcmp-bzdiff-bzmore-bzless-and-bzgrep-commands-explained-with-examples-6.png\" height=\"20\" alt=\"\" title=\"\"><\/a>\n<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>While the bzip2 command line utility can be used to compress files, there are many other tools that let you perform basic tasks &#8211; like comparing such files &#8211; without the need to uncompress them. Here, in this tutorial, we will discuss the basics of bzcmp, bzdiff, bzmore, bzless, and bzgrep commands using some easy &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-6117","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/6117","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=6117"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/6117\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=6117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=6117"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=6117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}