ウェブサイト検索

Linux の bzcmp、bzdiff、bzmore、bzless、および bzgrep コマンドの例による説明


このページでは

  1. Linux の bzcmp、bzdiff、bzmore、bzless、および bzgrep コマンド
    1. Q1. bzcmp および bzdiff コマンドはどのように機能しますか?
    2. Q2. bzmore および bzless コマンドはどのように機能しますか?
    3. Q3. bzgrep コマンドはどのように機能しますか?

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

    ただし、その前に、この記事のすべての例が Ubuntu 18.04 LTS マシンでテストされていることに言及する価値があります。

    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

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

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

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

    more と less と同様に、bzmore と bzless はどちらも CRT 表示用のフィルタですが、圧縮された bz2 ファイル用です。さらにわかりやすいように、bzmore のマニュアル ページからの抜粋を次に示します。

           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ですが、圧縮ファイル用です。以下は、このコマンドのマニュアル ページからの抜粋です。

           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 ページ (こちら) にアクセスしてください。