Session and utilities

The xzcat command

Shows the contents of a .xz file on standard output, without creating a file.

Syntax

xzcat archivo.xzTry it in the terminal →

Most useful options

-f, --forceIf the file is not in xz format, copies it as is to the output, like cat
-T, --threads <n>Uses several threads when decompressing since xz 5.4, if the file has several blocks
-q, --quietHides warnings. With two -q it also hides errors, without changing the exit status
-v, --verboseShows progress or a summary on the error output, without changing what is printed

Copy-ready examples

$ printf 'hola\n' > f.txt && xz -k f.txt && xzcat f.txt.xzcreates the file, compresses it and shows the content of the .xz.

Example output

hola
$ xzcat f.txt.xz | wc -ccounts the bytes of the content without touching the file.

Example output

5
$ xzcat -f f.txtf.txt is not compressed: with -f it is shown as it is, instead of an error.

Example output

hola
$ xzcat registro.log.xz | head -n 20reads the first lines of a compressed log without decompressing it to disk.

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
xzcat: f.txt: File format not recognizedThe file is not in xz format. xzcat does not show it as it is unless you use -f.Use xzcat -f to see it as it is, or cat if it is plain text.
xzcat: nope.xz: No such file or directoryThe name does not exist or is misspelled.List the folder with ls and copy the exact name.

Typical mistakes

  • xzcat does not delete the original or create any file: it only writes to the screen or a pipe.
  • With --single-stream, xzcat decompresses only the first stream and skips the rest. Without it, it continues with the following streams and data that is not xz causes an error.
  • Without -f, a file that is not xz causes an error even if it is readable text.

Differences from similar commands

  • zcat: reads .gz files. xzcat reads .xz; each one only understands its own format.
  • xz: xzcat is xz --decompress --stdout under another name. xz -dc archive.xz does the same.
  • cat: shows files as they are. xzcat decompresses first, so cat cannot read a .xz.

Related commands

FAQ

Does xzcat work for .gz?

No. For .gz use zcat, the equivalent tool for that format.

How do I search for a word inside a .xz?

Pipe the output into grep: xzcat archive.xz | grep word. There is no need to decompress to disk.

What happens with several concatenated .xz files?

The xz manual treats them as a single file; xzcat shows all the content in order.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course