Linux, コマンド · 1 min read · Sep 18, 2025

Linux bzcmp, bzdiff, bzmore, bzless, and bzgrep コマンドの説明と例

bzip2 コマンドラインユーティリティはファイルを圧縮できますが、他にもファイルを解凍せずに比較するなどの基本的な作業を行うためのツールが多数あります。このチュートリアルでは、bzcmp、bzdiff、bzmore、bzless、および bzgrep コマンドの基本を、わかりやすい例を使って説明します。

ただし、その前に、この記事のすべての例は Ubuntu 22.04 マシンでテストされていることをお伝えしておきます。

Linux bzcmp、bzdiff、bzmore、bzless、および bzgrep コマンド

これらのコマンドを Q&A スタイルで説明します。

Q1. bzcmp と bzdiff コマンドはどのように機能しますか?

名前が示すように、これらのコマンドは .bz2 ファイルを比較するために使用されます。以下がその構文です:

bzcmp [ cmp_options ] file1 [ file2 ]  
bzdiff [ diff_options ] file1 [ file2 ]

そして、man ページには次のように記載されています:

       Bzcmp  and  bzdiff  are  used  to invoke the cmp or the diff program on  
       bzip2 compressed files.  All options specified are passed  directly  to  
       cmp  or diff.  If only 1 file is specified, then the files compared are  
       file1 and an uncompressed file1.bz2.  If two files are specified,  then  
       they  are  uncompressed  if necessary and fed to cmp or diff.  The exit  
       status from cmp or diff is preserved.

bzcmp と bzdiff の基本的な例は次のとおりです:

bzcmp file1.bz2 file2.bz2
bzdiff file1.bz2 file2.bz2

次のスクリーンショットは、これらのコマンドによって生成された出力を示しています:

これらのコマンドは明示的にコマンドラインオプションを提供しませんが、bzcmp および bzdiff コマンドによって内部的に呼び出される cmp および diff コマンドのオプションを使用できます。

Q2. bzmore と bzless コマンドはどのように機能しますか?

more と less のように、bzmore と bzless は圧縮された bz2 ファイル用の CRT ビューイングフィルターです。より良いアイデアを得るために、bzmore の man ページからの抜粋を以下に示します:

       Bzmore is a filter which allows examination of compressed or plain text  
       files one screenful at a time on a soft-copy terminal.  bzmore works on  
       files  compressed with bzip2 and also on uncompressed files.  If a file  
       does not exist, bzmore looks for a file of the same name with the addi?  
       tion of a .bz2 suffix.  

       Bzmore  normally  pauses after each screenful, printing --More-- at the  
       bottom of the screen.  If the user then types a  carriage  return,  one  
       more line is displayed.  If the user hits a space, another screenful is  
       displayed.  Other possibilities are enumerated later.

もちろん、これらのコマンドを使用して圧縮ファイルを表示することもできます。以下はその例です:

Q3. bzgrep コマンドはどのように機能しますか?

おそらくもうお分かりのように、bzgrep もここで説明した他の bz シリーズコマンドのラインで機能します。具体的には、圧縮ファイル用の grep です。以下はこのコマンドの man ページからの抜粋です:

       Bzgrep is used to  invoke  the  grep  on  bzip2-compressed  files.  All  
       options  specified  are  passed directly to grep.  If no file is speci?  
       fied, then the standard input is decompressed if necessary and  fed  to  
       grep.   Otherwise the given files are uncompressed if necessary and fed  
       to grep.

bzgrep の使用例は次のとおりです:

bzgrep "menu" file1.bz2

次のスクリーンショットは出力を示しています:

結論

したがって、圧縮ファイル (.bz2) を扱っていて、検索、比較などの基本的な操作を行いたい場合は、これらのコマンドを使用できます。ここでは基本を説明しました。これらのツールに関する詳細については、man ページ (bzdiff、bzmore、および bzgrep) を参照してください。

Share: X/Twitter LinkedIn

新しい投稿を受信箱で受け取る

スパムはありません。いつでも購読を解除できます。