5

I'm using Red Hat Virtualization (RHV) and it logs all of its files in this directory:

$ pwd
/var/log/vdsm

$ ls | column -c 80 | head -10
backup          vdsm.log.34.xz      vdsm.log.69.xz
import          vdsm.log.35.xz      vdsm.log.6.xz
mom.log         vdsm.log.36.xz      vdsm.log.70.xz
mom.log.1       vdsm.log.37.xz      vdsm.log.71.xz
mom.log.2       vdsm.log.38.xz      vdsm.log.72.xz
mom.log.3       vdsm.log.39.xz      vdsm.log.73.xz
mom.log.4       vdsm.log.3.xz       vdsm.log.74.xz
mom.log.5       vdsm.log.40.xz      vdsm.log.75.xz
supervdsm.log   vdsm.log.41.xz      vdsm.log.76.xz
upgrade.log     vdsm.log.42.xz      vdsm.log.77.xz

I've used the z* tools such as zgrep & zcat to look through .gz & .Z files but it doesn't appear to deal with .xz compression.

What's an easy way to grep through a directory of .xz files?

slm
  • 363,520
  • 117
  • 767
  • 871

1 Answers1

5

If you look through the tooling provided by the xz RPM on RHEL/CentOS/Fedora distros this RPM includes a few helper wrapper scripts that you can enlist to make short work of this.

Identifying a Lead

With issues such as this I typically start by locating the RPMs that provide the tooling. In this case xz is the compression CLI so let's locate it and see what RPM provides it:

$ type -f xz
xz is /usr/bin/xz

$ rpm -qf /usr/bin/xz
xz-5.2.2-1.el7.x86_64

Now let's look and see if it provides anything with the name grep in it:

$ rpm -ql xz | grep -E 'bin/.*grep'
/usr/bin/xzegrep
/usr/bin/xzfgrep
/usr/bin/xzgrep

It does. So let's try using xzgrep since that's what we're after in terms of functionality:

$ xzgrep -l ocp-app-01c *
mom.log.4
vdsm.log.2.xz
vdsm.log.81.xz

NOTE: Above we're looking for occurrences of ocp-app-01c and printing files that contain it.

Usage

The usage is identical to grep:

$ xzgrep --help
Usage: xzgrep [OPTION]... [-e] PATTERN [FILE]...
Look for instances of PATTERN in the input FILEs, using their
uncompressed contents if they are compressed.

OPTIONs are the same as for 'grep'.

Report bugs to <[email protected]>.
slm
  • 363,520
  • 117
  • 767
  • 871