Reading gz files with zcat
The Debian Policy Manual dictates that all packages should come with documentation. In order to save space in the debian archive these documents need to be compressed with gzip
. There are a ton of these files floating around in the /usr/share/doc
directory. Recently I wanted to read some of the documentation. If you try to open the file with cat
it spits out binary gibberish. You can of course unzip the file as you normally would and open it up that way, but it turns out there is an easier way. Using zcat
you can read the contents of compressed files just like you would with cat
.
zcat is identical to gunzip -c. (On some systems, zcat may be installed as gzcat to preserve the original link to compress.) zcat uncompresses either a list of files on the command line or its standard input and writes the uncompressed data on standard output. zcat will uncompress files that have the correct magic number whether they have a .gz suffix or not. GZIP(1) man page.By default, this will put all of the output into your terminal window, which is fine for most files. The other place where this can come in handy is when you are trying to look through compressed log files. In this case, having to scroll around the terminal may not be a great option. You can pipe the output of zcat into other programs such as
less
in order to be able to page through long files. For example, if I wanted to read the first 10 lines of a compressed log file, I could do so with the following command:
levlaz@debvm:/var/log$ sudo zcat syslog.2.gz | head -n 10
May 2 22:27:43 debvm rsyslogd: [origin software="rsyslogd" swVersion="8.4.2" x-pid="585" x-info="https://www.rsyslog.com"] start May 2 22:27:43 debvm kernel: [ 0.000000] ACPI: LAPIC_NMI (acpi_id[0x1a] high edge lint[0x1]) May 2 22:27:43 debvm kernel: [ 0.000000] ACPI: LAPIC_NMI (acpi_id[0x1b] high edge lint[0x1]) May 2 22:27:43 debvm kernel: [ 0.000000] ACPI: LAPIC_NMI (acpi_id[0x1c] high edge lint[0x1]) May 2 22:27:43 debvm kernel: [ 0.000000] ACPI: LAPIC_NMI (acpi_id[0x1d] high edge lint[0x1]) May 2 22:27:43 debvm kernel: [ 0.000000] ACPI: LAPIC_NMI (acpi_id[0x1e] high edge lint[0x1]) May 2 22:27:43 debvm kernel: [ 0.000000] ACPI: LAPIC_NMI (acpi_id[0x1f] high edge lint[0x1]) May 2 22:27:43 debvm kernel: [ 0.000000] ACPI: LAPIC_NMI (acpi_id[0x20] high edge lint[0x1]) May 2 22:27:43 debvm kernel: [ 0.000000] ACPI: LAPIC_NMI (acpi_id[0x21] high edge lint[0x1]) May 2 22:27:43 debvm kernel: [ 0.000000] ACPI: LAPIC_NMI (acpi_id[0x22] high edge lint[0x1])
Thank you for reading! Share your thoughts with me on bluesky, mastodon, or via email.
Check out some more stuff to read down below.
Most popular posts this month
- 2024
- Reinstalling Windows at 1am
- SQLite DB Migrations with PRAGMA user_version
- My Custom Miniflux CSS Theme
- How to Disable Wayland in Debian Testing
Recent Favorite Blog Posts
This is a collection of the last 8 posts that I bookmarked.
- Future Fonts from Blog – Brad Frost
- 21st Century C++ from Communications of the ACM
- Submarines DevCon 2025 Keynote Speech from JoshHaines.com
- How I Use AI: Meet My Promptly Hired Model Intern from Armin Ronacher's Thoughts and Writings
- DeepSeek from Maggie Appleton
- Digital Reality Digital Shock from Christopher Butler
- 10 habits to help becoming a Debian Maintainer from Optimized by Otto
- Tiny corners from Manuel Moreale RSS Feed
Articles from blogs I follow around the net
Notes from Alexander Petros’ “Building the Hundred-Year Web Service”
I loved this talk from Alexander Petros titled “Building the Hundred-Year Web Service”. What follows is summation of my note-taking from watching the talk on YouTube. Is what you’re building for future generations: Useful for them? Maintainable by them? Adapt…
via Jim Nielsen’s Blog May 14, 2025Open Up, Episode 2: Fundamentals, Principles, Navigating an Imperfect World, Collaboration, and Old Friends
I’m late in posting this because boy oh boy, there’s been a lot going on. But Episode 2 of our show Open Up is out! Geoff and I tackled some great questions and covered a lot of ground in this […]
via Blog – Brad Frost May 14, 2025Your license is a scam
Good morning. Good morning sir! How can I help you? Hello, hi. I was interested in buying one of your cars, the Model A. I really like it and it seems perfect for me. That’s an excellent choice! Model A is a great car, the price starts at 20 …
via Manuel Moreale May 14, 2025Generated by openring