Linux bzcmp、bzdiff、bzmore、bzless 和 bzgrep 命令的解释与示例
在此页
- Linux bzcmp、bzdiff、bzmore、bzless 和 bzgrep 命令
- Q1。 bzcmp 和 bzdiff 命令如何工作?
- Q2。 bzmore 和 bzless 命令如何工作?
- Q3。 bzgrep 命令如何工作?
虽然 bzip2 命令行实用程序可用于压缩文件,但还有许多其他工具可让您执行基本任务(如比较此类文件)而无需解压缩它们。在本教程中,我们将使用一些易于理解的示例来讨论 bzcmp、bzdiff、bzmore、bzless 和 bzgrep 命令的基础知识。
但在此之前,值得一提的是,本文中的所有示例都已在 Ubuntu 18.04 LTS 机器上进行了测试。
Linux bzcmp、bzdiff、bzmore、bzless 和 bzgrep 命令
我们将使用问答式的演示方式讨论这些命令中的每一个。
Q1。 bzcmp 和 bzdiff 命令如何工作?
顾名思义,这些命令用于比较 .bz2 文件。以下是它们的语法:
bzcmp [ cmp_options ] file1 [ file2 ]
bzdiff [ diff_options ] file1 [ file2 ]这是手册页关于它们的内容:
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),并希望执行搜索、比较等基本操作,您可以使用这些命令。我们在这里讨论了基础知识。有关这些工具的更多信息,请访问它们的手册页(此处)。