Session and utilities

The bzcat command

Shows the contents of a .bz2 file on screen, without decompressing it to disk.

Syntax

bzcat [-s] [archivo.bz2...]Try it in the terminal →

Most useful options

-s, --smallDecompresses with less memory, at the cost of running at about half the normal speed. Useful with little RAM
-h, --helpShows the command help and exits

Copy-ready examples

$ printf 'hola\n' > f.txt && bzip2 -k f.txt && bzcat f.txt.bz2creates a test .bz2 file and shows it on screen.

Example output

hola
$ bzcat registro.log.bz2 | grep ERRORsearches a compressed log for lines without writing it to disk.
$ bzcat -s copia.tar.bz2 | tar -tf -lists the contents of a tar.bz2 with little memory, without extracting it.
$ bzcat primera.txt.bz2 segunda.txt.bz2shows two compressed files one after the other.

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

Common errors

MessageCauseFix
bzcat: Can't open input file nofile.bz2: No such file or directory.The file does not exist or the name is misspelled.List the folder with ls and type the exact name, including the .bz2 extension.

Typical mistakes

  • bzcat does not delete the .bz2 or create any file: the output goes to standard output. To keep it, redirect with > name.
  • With several files, their contents come out one after another in the same output, with no separator between them.
  • It only understands the bzip2 format. For .gz use zcat, and for .xz use xzcat. With no files, it reads standard input and waits if nothing arrives.

Differences from similar commands

  • bzip2: bzip2 -dc does the same as bzcat. Without -c, though, -d replaces the .bz2 with the uncompressed file.
  • bunzip2: decompresses to disk and replaces the .bz2 unless you use -k. bzcat only writes to standard output.
  • zcat: does the same for .gz files. zcat does not understand .bz2.

Related commands

FAQ

Does bzcat delete or change the compressed file?

No. It writes the result to standard output and leaves the .bz2 untouched. If you want the uncompressed file on disk, use bunzip2 -k, which keeps the original.

Does it work with a .bz2 made of several compressed files joined together?

Yes. bunzip2 correctly decompresses a file made of several compressed files joined together, and bzcat is the same as bzip2 -dc.

How do I save what bzcat shows into a file?

With a redirection: bzcat f.txt.bz2 > f.txt. Be careful, because > overwrites the destination if it already exists.

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