Home / Alt manpages / xzless(1)

  • xzless(1)
  • User command
  • linux

Read Compressed Text Safely with xzless

xzless hands an xz or lzma text file straight to less without ever writing a decompressed copy to disk. You get to scroll, search and quit with the pager controls you already know. The examples match the installed XZ Utils command here: /usr/bin/xzless reports version 5.4.5, supplied by the distro's xz-utils package version 5.6.1+really5.4.5-1ubuntu0.3.

Allow about ten minutes. You need a shell, xz-utils, less, and a compressed text file. This guide only reads data: no overwriting the archive, no extracted file left behind.

1. Check which xzless will run

Start by checking the command your PATH actually picks:

$ command -v xzless
/home/linuxbrew/.linuxbrew/bin/xzless
$ xzless --version
xzless (XZ Utils) 5.8.4

On this machine the interactive shell finds a Linuxbrew build first, while the distro copy at /usr/bin/xzless reports 5.4.5. Both give the same documented interface for this guide, but the distinction matters when you are debugging a script or comparing output between hosts. Force the distro copy with the absolute path:

$ /usr/bin/xzless --version
xzless (XZ Utils) 5.4.5

Checkpoint

Record the path and version before reporting a version-specific problem. Do not infer the package version from the command name alone.

2. Open one compressed text file

Pass the archive as an ordinary argument:

$ xzless /var/log/example.log.xz

xzless decompresses and hands the text to less, which opens interactively, so the command appears to hang until you quit it. Press q to return to the shell. The usual controls apply: Space pages forward, b pages back, /pattern searches forward and n repeats it. The exact key set belongs to your installed less, so check man less if a key does something unexpected.

Treat this as a text viewer, not a binary inspector. Decompressed binary data can contain control characters that make a terminal misbehave. If a file came from somewhere you do not fully trust, redirect the output somewhere controlled or use a tool built for that file type instead.

3. Open several files and keep their names visible

Give multiple archive paths to move between related files in one session:

$ xzless /var/log/example.log.2.xz /var/log/example.log.1.xz

less treats these as separate inputs, moves between them with its own commands, and shows the current one on its status line. Quote any path that contains spaces or shell metacharacters:

$ xzless -- "$HOME/archive notes/meeting.log.xz"

The -- marks the end of options, so a filename that happens to start with a hyphen is not mistaken for a less option. It does not make an untrusted path safe on its own, so quote it as shown and never evaluate it as shell code.

4. Stream compressed input through standard input

If the data is already mid-pipeline, drop the file argument:

$ xz -cd -- /var/log/example.log.xz | xzless
sample log lines appear in less

This is worth reaching for when another command selected the archive, or you need a preprocessing step before viewing. A direct invocation is usually easier to audit, and the manpage explicitly defines xzless with no file argument as reading standard input.

Do not treat a pipeline's exit status as proof the whole operation worked: a decompressor can fail before the pager even exits, and a shell pipeline typically reports only the last command's status. If a script needs to catch decompression errors, test the archive separately first.

5. Use lzless when compatibility requires it

lzless is the compatibility name kept for people used to the older LZMA Utils naming, and it accepts the same file and standard-input forms:

$ lzless /srv/archive/config.txt.lzma
$ lzless --version
xzless (XZ Utils) 5.4.5

The alias does not imply an older toolchain: the installed command supports both xz and lzma text through either name. Prefer xzless in new documentation unless an existing script already depends on lzless.

6. Understand the environment boundary

xzless sets LESSOPEN so less knows to invoke the xz decompressor, and it sets LESSMETACHARS unless that variable is already present. That is the whole trick behind handing compressed files straight to a pager.

Unlike xzmore, there is no environment variable here to switch the pager itself. For different behaviour, reach for an option your installed less already supports:

$ xzless -N /var/log/example.log.xz

-N is a less option that turns on line numbers. Verify any option against man less on the target host rather than assuming every version defaults the same way.

Done means

  • Checked the resolved command and version when reproducibility mattered.
  • Viewed an xz or lzma text file without extracting it.
  • Know that q exits the pager and /pattern searches it.
  • Passed several files, or omitted the file argument for standard input.
  • Treated lzless as a compatibility alias and kept pager options where they belong, with less.