GNU/Linux >> Linux の 問題 >  >> Linux

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

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

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

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

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

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

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

ますます多くの場合と同様に、bzmoreとbzlessはどちらもCRT表示用のフィルターですが、圧縮されたbz2ファイル用です。さらに良いアイデアを提供するために、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ですが、圧縮ファイル用です。以下は、このコマンドのマニュアルページからの抜粋です。

       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)を処理していて、検索、比較などの基本的な操作を実行したい場合は、これらのコマンドを使用できます。ここでは基本について説明しました。これらのツールの詳細については、マニュアルページ(ここ、ここ、およびここ)にアクセスしてください。


Linux
  1. Linuxのshutdownコマンドを例で説明

  2. Linuxコマンド-概要と例

  3. Linuxでファイルとディレクトリを圧縮する方法(例付き)

  1. Linuxのヘッドコマンドとテールコマンドを例で説明

  2. Linux Tracerouteコマンド、例を使用して説明

  3. 例を挙げて説明する初心者向けの20の基本的なLinuxコマンド

  1. Linuxでの例で「cat」および「tac」コマンドを使用する方法

  2. findおよびduコマンドを使用してLinuxで大きなファイルを検索する方法

  3. 「cp」および「mv」コマンドを使用してLinuxでファイルとディレクトリをコピー/移動する方法