This manual is for Zutils (version 1.13, 23 January 2024).
Copyright © 2009-2024 Antonio Diaz Diaz.
This manual is free documentation: you have unlimited permission to copy, distribute, and modify it.
Zutils is a collection of utilities able to process any combination of compressed and uncompressed files transparently. If any file given, including standard input, is compressed, its decompressed content is used. Compressed files are decompressed on the fly; no temporary files are created. Data format is detected by its identifier string (magic bytes), not by the file name extension. Empty files are considered uncompressed.
These utilities are not wrapper scripts but safer and more efficient C++ programs. In particular the option --recursive is very efficient in those utilities supporting it.
The utilities provided are zcat, zcmp, zdiff,
zgrep, ztest, and zupdate.
The formats supported are bzip2, gzip,
lzip, xz, and zstd.
Zutils uses external compressors. The compressor to be used for each format
is configurable at runtime.
zcat, zcmp, zdiff, and zgrep are improved replacements for the shell scripts provided by GNU gzip. ztest is unique to zutils. zupdate is similar to gzip's znew.
When zcat, zcmp, zdiff, or zgrep need to try compressed file names, the search order is: lzip, gzip, bzip2, zstd, xz. (file.[lz|gz|bz2|zst|xz]).
NOTE: Bzip2 and lzip provide well-defined values of exit status, which makes them safe to use with zutils. Gzip and xz may return ambiguous warning values, making them less reliable back ends for zutils. Zstd currently does not even document its exit status in its man page. See compressor-requirements.
FORMAT NOTE 1: The option --format allows the processing of a subset of formats in recursive mode and when trying compressed file names. For example, use the following command to search for the string 'foo' in gzip and lzip files only: 'zgrep foo -r --format=gz,lz somedir somefile.tar'.
FORMAT NOTE 2: The standard POSIX compress format (.Z) is obsolete and is only supported through gzip. For this to work, the gzip program used (for example GNU gzip) must be able to decompress .Z files.
LANGUAGE NOTE: Uncompressed = not compressed = plain data; it may never have been compressed. Decompressed is used to refer to data which have undergone the process of decompression.
The following options: are available in all the utilities. Rather than writing identical descriptions for each of the programs, they are described here. Remember to prepend ./ to any file name beginning with a hyphen, or use '--'.
-h
--help
-V
--version
-M
format_list--format=
format_listEach format in format_list enables file names with the following extensions:
bz2 | enables | .bz2 .tbz .tbz2
|
gz | enables | .gz .tgz .Z
|
lz | enables | .lz .tlz
|
xz | enables | .xz .txz
|
zst | enables | .zst .tzst
|
un | enables | any other file name
|
-N
--no-rcfile
--bz2=
command--gz=
command--lz=
command--xz=
command--zst=
commandNumbers given as arguments to options may be expressed in decimal, hexadecimal, or octal (using the same syntax as integer constants in C++), and may be followed by a multiplier and an optional 'B' for "byte".
Table of SI and binary prefixes (unit multipliers):
Prefix | Value | | | Prefix | Value
|
k | kilobyte (10^3 = 1000) | | | Ki | kibibyte (2^10 = 1024)
|
M | megabyte (10^6) | | | Mi | mebibyte (2^20)
|
G | gigabyte (10^9) | | | Gi | gibibyte (2^30)
|
T | terabyte (10^12) | | | Ti | tebibyte (2^40)
|
P | petabyte (10^15) | | | Pi | pebibyte (2^50)
|
E | exabyte (10^18) | | | Ei | exbibyte (2^60)
|
Z | zettabyte (10^21) | | | Zi | zebibyte (2^70)
|
Y | yottabyte (10^24) | | | Yi | yobibyte (2^80)
|
R | ronnabyte (10^27) | | | Ri | robibyte (2^90)
|
Q | quettabyte (10^30) | | | Qi | quebibyte (2^100)
|
zutils.conf is the runtime configuration file for zutils. In it you may define the compressor name and options to be used for each format. zutils.conf is optional; you don't need to install it in order to run zutils.
The compressors specified in the command line override those specified in zutils.conf.
You may copy the system zutils.conf file ${sysconfdir}/zutils.conf to $XDG_CONFIG_HOME/zutils.conf and customize these options as you like. (XDG_CONFIG_HOME defaults to $HOME/.config). The file syntax is fairly obvious (and there are further instructions in it):
<format> = <compressor> [options]
where <format> is one of 'bz2', 'gz', 'lz', 'xz', or 'zst'.
zcat copies each file argument to standard output in sequence. If any file given is compressed, its decompressed content is copied. If a file given does not exist, and its name does not end with one of the known extensions, zcat tries the compressed file names corresponding to the formats supported until one is found. See search-order. If a file fails to decompress, zcat continues copying the rest of the files.
If a file is specified as '-', data are read from standard input, decompressed if needed, and sent to standard output. Data read from standard input must be of the same type; all uncompressed or all in the same compressed format.
If no files are specified, recursive searches examine the current working directory, and nonrecursive searches read standard input.
The format for running zcat is:
zcat [options] [files]
Exit status is 0 if no errors occurred, 1 otherwise.
zcat supports the following options:
-A
--show-all
-b
--number-nonblank
-e
-E
--show-ends
-n
--number
-O
format--force-format=
format-q
--quiet
-r
--recursive
-R
--dereference-recursive
-s
--squeeze-blank
-t
-T
--show-tabs
-v
--show-nonprinting
--verbose
zcmp compares two files and, if they differ, writes to standard output the first byte and line number where they differ. Bytes and lines are numbered starting with 1. A hyphen '-' used as a file argument means standard input. If any file given is compressed, its decompressed content is used. Compressed files are decompressed on the fly; no temporary files are created.
The format for running zcmp is:
zcmp [options] file1 [file2]
This compares file1 to file2. The standard input is used only if file1 or file2 refers to standard input. If file2 is omitted zcmp tries to compare file1 with the corresponding uncompressed file (if file1 is compressed), and then with the corresponding compressed files of the remaining formats until one is found. See search-order.
An exit status of 0 means no differences were found, 1 means some differences were found, and 2 means trouble.
zcmp supports the following options:
-b
--print-bytes
-H
--hexadecimal
-i
size--ignore-initial=
size-l
--list
-n
count--bytes=
count-O [
format1][,
format2]
--force-format=[
format1][,
format2]
-q
--quiet
--silent
-s
--script
-v
--verbose
zdiff compares two files and, if they differ, writes to standard output the differences line by line. A hyphen '-' used as a file argument means standard input. If any file given is compressed, its decompressed content is used. zdiff is a front end to the program diff and has the limitation that messages from diff refer to temporary file names instead of those specified.
The format for running zdiff is:
zdiff [options] file1 [file2]
This compares file1 to file2. The standard input is used only if file1 or file2 refers to standard input. If file2 is omitted zdiff tries to compare file1 with the corresponding uncompressed file (if file1 is compressed), and then with the corresponding compressed files of the remaining formats until one is found. See search-order.
An exit status of 0 means no differences were found, 1 means some differences were found, and 2 means trouble.
zdiff supports the following options (some options only work if the diff program used supports them):
-a
--text
-b
--ignore-space-change
-B
--ignore-blank-lines
-c
-C
n--context=
n-d
--minimal
-E
--ignore-tab-expansion
-i
--ignore-case
-O [
format1][,
format2]
--force-format=[
format1][,
format2]
-p
--show-c-function
-q
--brief
-s
--report-identical-files
-t
--expand-tabs
-T
--initial-tab
-u
-U
n--unified=
n-v
--verbose
-w
--ignore-all-space
-W
columns--width=
columns-y
--side-by-side
zgrep is a front end to the program grep that allows transparent search on any combination of compressed and uncompressed files. If any file given is compressed, its decompressed content is used. If a file given does not exist, and its name does not end with one of the known extensions, zgrep tries the compressed file names corresponding to the formats supported until one is found. See search-order. If a file fails to decompress, zgrep continues searching the rest of the files.
If a file is specified as '-', data are read from standard input, decompressed if needed, and fed to grep. Data read from standard input must be of the same type; all uncompressed or all in the same compressed format.
If no files are specified, recursive searches examine the current working directory, and nonrecursive searches read standard input.
For efficiency reasons, zgrep does not always read all its input. For example, the shell command 'base64 -d foo | zgrep -q X' can cause zgrep to exit immediately after reading a line containing 'X', without bothering to read the rest of its input data. This in turn can cause base64 to exit with a nonzero status because base64 cannot write to its output pipe after zgrep exits.
The format for running zgrep is:
zgrep [options] pattern [files]
An exit status of 0 means at least one match was found, 1 means no matches were found, and 2 means trouble.
zgrep supports the following options (Some options only work if the grep program used supports them. Options -h, -H, -r, -R, and -Z are managed by zgrep and not passed to grep):
-a
--text
-A
n--after-context=
n-b
--byte-offset
-B
n--before-context=
n-c
--count
-C
n--context=
n--color[=
when]
-e
pattern--regexp=
pattern-E
--extended-regexp
-f
file--file=
file-F
--fixed-strings
-G
--basic-regexp
-h
--no-filename
-H
--with-filename
-i
--ignore-case
-I
-l
--files-with-matches
-L
--files-without-match
--label=
label--line-buffered
-m
n--max-count=
n-n
--line-number
-o
--only-matching
-O
format--force-format=
format-P
--perl-regexp
-q
--quiet
--silent
-r
--recursive
-R
--dereference-recursive
-s
--no-messages
-T
--initial-tab
-U
--binary
-v
--invert-match
--verbose
-w
--word-regexp
-x
--line-regexp
-Z
--null
ztest checks the integrity of the compressed files specified. It also warns if an uncompressed file has a compressed file name extension, or if a compressed file has a wrong compressed extension. Uncompressed files are otherwise ignored. If a file is specified as '-', the integrity of compressed data read from standard input is checked. Data read from standard input must be all in the same compressed format. If a file fails to decompress, does not exist, can't be opened, or is a terminal, ztest continues testing the rest of the files. A final diagnostic is shown at verbosity level 1 or higher if any file fails the test when testing multiple files.
If no files are specified, recursive searches examine the current working directory, and nonrecursive searches read standard input.
Bzip2, gzip, and lzip are the primary formats. Xz and zstd are optional. If the decompressor for the xz or zstd formats is not found, the corresponding files are ignored.
Note that error detection in the xz format is broken. First, some xz files lack integrity information. Second, not all xz decompressors can check the integrity of all xz files. Third, section 2.1.1.2 'Stream Flags' of the xz format specification allows xz decompressors to produce garbage output without issuing any warning. Therefore, xz files can't always be checked as reliably as files in the other formats can.
The format for running ztest is:
ztest [options] [files]
Exit status is 0 if all compressed files check OK, 1 if environmental problems (file not found, invalid command-line options, I/O errors, etc), 2 if any compressed file is corrupt or invalid, or if any file has an incorrect file name extension.
ztest supports the following options:
-O
format--force-format=
format-q
--quiet
-r
--recursive
-R
--dereference-recursive
-v
--verbose
zupdate recompresses files from bzip2, gzip, xz, and zstd formats to lzip format. Each original is compared with the new file and then deleted. Only regular files with standard file name extensions are recompressed, other files are ignored. Compressed files are decompressed and then recompressed on the fly; no temporary files are created. If an error happens while recompressing a file, zupdate exits immediately without recompressing the rest of the files. The lzip format is chosen as destination because it is the most appropriate for long-term archiving.
If no files are specified, recursive searches examine the current working directory, and nonrecursive searches do nothing.
If the lzip-compressed version of a file already exists, the file is skipped unless the option --force is given. In this case, if the comparison with the existing lzip version fails, an error is returned and the original file is not deleted. The operation of zupdate is meant to be safe and not cause any data loss. Therefore, existing lzip-compressed files are never overwritten nor deleted.
Combining the options --force and --keep, as in 'zupdate -f -k *.gz', checks that there are no differences between each pair of files in a multiformat set of files.
The names of the original files must have one of the following extensions:
'.bz2', '.gz', '.xz', '.zst', or '.Z', which are
recompressed to '.lz';
'.tbz', '.tbz2', '.tgz', '.txz', or '.tzst', which
are recompressed to '.tlz'.
Keeping the combined extensions ('.tgz' --> '.tlz') may be
useful when recompressing Slackware packages, for example.
Bzip2, gzip, and lzip are the primary formats. Xz and zstd are optional. If the decompressor for the xz or zstd formats is not found, the corresponding files are ignored.
Recompressing a file is much like copying or moving it. Therefore zupdate preserves the access and modification dates, permissions, and, if you have appropriate privileges, ownership of the file just as 'cp -p' does. (If the user ID or the group ID can't be duplicated, the file permission bits S_ISUID and S_ISGID are cleared).
The format for running zupdate is:
zupdate [options] [files]
Exit status is 0 if all the compressed files were successfully recompressed (if needed), compared, and deleted (if requested). 1 if a non-fatal error occurred (file not found or not regular, or has invalid format, or can't be deleted). 2 if a fatal error occurred (invalid command-line options, compressor can't be run, or comparison fails).
zupdate supports the following options:
-d
dir--destdir=
dirThis option allows recompressing files from a read-only file system to
another place without the need to copy or link them to the destination
directory first. (Remember to use option --keep when recompressing
read-only files to avoid warnings about files that can't be deleted).
-e
--expand-extensions
-f
--force
-i
--ignore-errors
-k
--keep
-l
--lzip-verbose
-q
--quiet
-r
--recursive
-R
--dereference-recursive
-v
--verbose
-0 .. -9
--lz=
commandThere are probably bugs in zutils. There are certainly errors and omissions in this manual. If you report them, they will get fixed. If you don't, no one will ever know about them and they will remain unfixed for all eternity, if not longer.
If you find a bug in zutils, please send electronic mail to zutils-bug@nongnu.org. Include the version number, which you can find by running 'zupdate --version'.