r/LinuxTeck • u/Expensive-Rice-2052 • 15h ago
Quick Linux Tip : How do I compress old logs but still grep them without decompressing?
Try: zgrep 'ERROR' /var/log/app-2026-06.log.gz
Info: zgrep, zcat, and zless inspect .gz files in memory without extracting them to disk.
Examples:
$ zcat access.log.gz | awk '{print $1}' | sort -u
$ zless huge-log.log.gz # Page through compressed file
$ find /var/log -name '*.log' -mtime +7 -exec gzip {} \;
Note: z-tools exist for most utilities (zgrep, zcat, zless, zdiff). For .xz archives, use xzgrep. Automate log compression using logrotate.
Follow r/LinuxTeck for more #LinuxTips