Session and utilities
The bzcat command
Shows the contents of a .bz2 file on screen, without decompressing it to disk.
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 exitsCopy-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
| Message | Cause | Fix |
|---|---|---|
| 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
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