Command documentation sourced from the linux-command project This comprehensive command reference is part of the linux-command documentation project.
bzless - File Viewer for bzip2 Compressed Files
The bzless command is a file viewer that allows you to browse the contents of bzip2 compressed files (.bz2) without decompressing them first. It provides the same functionality as the less command but works directly with bzip2-compressed files, decompressing them on-the-fly as you scroll through the content. This makes it an efficient tool for viewing large compressed text files, logs, and documents while conserving disk space and memory.
Basic Syntax
bzless [OPTIONS] FILE...
Key Features
- On-the-fly decompression - Reads bzip2 files without extracting them
- Interactive navigation - Full less-style navigation commands
- Search functionality - Search within compressed files
- Multiple file viewing - View multiple files in sequence
- Line numbers - Optional line numbering
- Pattern matching - Regular expression search support
Common Options
Display Options
-N, --LINE-NUMBERS- Display line numbers-e, --QUIT-AT-EOF- Exit automatically at end of file-F, --quit-if-one-screen- Quit if entire file fits on first screen-R, --RAW-CONTROL-CHARS- Output raw control characters-M, --LONG-PROMPT- Show more detailed prompt
Search Options
-i, --ignore-case- Search case-insensitively-I, --IGNORE-CASE- Always search case-insensitively-G, --HIGHLIGHT-TOGGLE- Toggle highlight on/off-w, --hilite-search- Highlight first unmatched search-W, --HILITE-UNREAD- Highlight unread text
Navigation Options
-s, --squeeze-blank-lines- Squeeze multiple blank lines-j, --jump-target=N- Target line for jumps-k, --lesskey-file=FILE- Use alternative lesskey file-D, --termcap=STRING- Set terminal capabilities
Navigation Commands
Movement Commands
h,H- Show help screenq,Q- QuitSPACE,f- Forward one screenb- Backward one screenj,ENTER- Forward one linek- Backward one lineg- Go to beginning of fileG- Go to end of file
Jumping
<number>G- Go to line number<percentage>p- Go to percentage position<space>G- Go to line with that number
Searching
/pattern- Search forward for pattern?pattern- Search backward for patternn- Repeat previous search (forward)N- Repeat previous search (backward)&pattern- Display only matching lines
Marking
m<letter>- Set mark' <letter>- Go to mark
Usage Examples
Basic File Viewing
Viewing Compressed Files
# View a bzip2 compressed file
bzless document.txt.bz2
# View multiple files in sequence
bzless file1.txt.bz2 file2.txt.bz2 file3.txt.bz2
# View file with line numbers
bzless -N log.txt.bz2
# View and quit at end of file
bzless -e short_file.txt.bz2
# Exit if file fits on one screen
bzless -F small_config.txt.bz2
System Log Viewing
# View compressed system logs
bzless /var/log/syslog.1.bz2
# View with line numbers for debugging
bzless -N /var/log/auth.log.2.bz2
# View multiple rotated logs
bzless /var/log/apache2/access.log.*.bz2
# View logs and quit at end
bzless -e /var/log/messages.1.bz2
Searching Within Files
Basic Search
# View file and search for error messages
bzless application.log.bz2
# Press: /ERROR
# Search for specific IP address
bzless access.log.bz2
# Press: /192\.168\.1\.100
# Search backward for warning messages
bzless system.log.bz2
# Press: ?WARNING
Advanced Search Patterns
# Case-insensitive search
bzless -i document.txt.bz2
# Press: /error
# Regular expression search for email addresses
bzless data.txt.bz2
# Press: /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
# Search for lines starting with ERROR
bzless -G log.txt.bz2
# Press: /^ERROR
# Search and display only matching lines
bzless -G & "ERROR" critical.log.bz2
File Navigation
Line Navigation
# Jump to specific line
bzless large_file.txt.bz2
# Press: 1000G (go to line 1000)
# Go to middle of file
bzless document.txt.bz2
# Press: 50% (go to 50% position)
# Go to end and scroll backward
bzless log.txt.bz2
# Press: G, then b, b, b...
Mark Navigation
# Set marks for easy navigation
bzless manual.txt.bz2
# Press: ma (set mark A)
# Press: mb (set mark B)
# Press: 'a (go to mark A)
# Press: 'b (go to mark B)
Practical Examples
System Administration
Log Analysis
# View compressed application logs for errors
bzless -N application.log.1.bz2
# Search for: /ERROR
# Monitor web server logs for specific patterns
bzless -i -G /var/log/nginx/access.log.*.bz2
# Search for: /404
# View authentication logs for failed attempts
bzless -N /var/log/auth.log.2.bz2
# Search for: /FAIL
Configuration Management
# View compressed backup configurations
bzless /backup/config/etc-$(date +%Y%m%d).tar.bz2
# Compare compressed configuration files
bzless -N /backup/nginx.conf.20231201.bz2
# View system information dumps
bzless /var/log/dmesg.1.bz2
Development Workflow
Code Review
# View compressed code archives
bzless source-$(date +%Y%m%d).tar.bz2
# Search for specific functions in compressed source
bzless application-code.bz2
# Search: /function main
# View compressed documentation
bzless -N manual.pdf.txt.bz2
Debugging
# View compressed debug logs
bzless -N debug.log.1.bz2
# Search for stack traces
bzless crash.log.bz2
# Search: /Stack trace
# View compressed test results
bzless test-results.txt.bz2
Data Analysis
Large File Processing
# View large compressed datasets efficiently
bzless large_dataset.csv.bz2
# Search for specific data patterns
bzless sales_data.bz2
# Search: /2023-12
# Analyze compressed log files
bzless -G access_log.bz2
# Display only error lines: & "HTTP/1.1\" [45][0-9][0-9]"
Report Generation
# View compressed monthly reports
bzless -N monthly_report_$(date +%Y%m).txt.bz2
# Search for specific metrics
bzless performance_report.bz2
# Search: /CPU usage
Advanced Usage
Multiple File Operations
File Sequencing
# View multiple compressed logs in order
bzless /var/log/syslog.1.bz2 /var/log/syslog.2.bz2
# Navigate between files
# Press: :n (next file)
# Press: :p (previous file)
# Press: :x (first file)
# Press: :d (remove file from list)
File Information
# Show current file information
bzless document.txt.bz2
# Press: = (show file info and current position)
# Show file list when viewing multiple files
bzless file1.bz2 file2.bz2 file3.bz2
# Press: * (show file list)
Search Optimization
Efficient Searching
# View with no highlighting for speed
bzless -G huge_file.bz2
# Case-insensitive search by default
bzless -I text_file.bz2
# Use lesskey file for custom key bindings
bzless -k ~/.lesskey config.txt.bz2
Terminal Integration
Custom Display
# Display raw control characters for debugging
bzless -R binary_log.bz2
# Show detailed prompts
bzless -M long_document.bz2
# Squeeze multiple blank lines
bzless -s formatted_text.bz2
Automation and Scripting
Shell Script Integration
Log Monitoring Script
#!/bin/bash
# Monitor compressed logs for specific patterns
LOG_DIR="/var/log"
PATTERN="ERROR"
COMPRESSED_LOGS=$(find "$LOG_DIR" -name "*.bz2" -mtime -7)
for log in $COMPRESSED_LOGS; do
echo "=== Checking $log ==="
bzless -N "$log" <<< "/$PATTERN"
done
Batch File Viewer
#!/bin/bash
# View all compressed files in a directory
for file in *.bz2; do
if [ -f "$file" ]; then
echo "=== Viewing: $file ==="
bzless -N "$file"
echo "Press Enter to continue to next file..."
read -r
fi
done
Pipeline Integration
Filter Compressed Content
# Count lines in compressed file
bzless large_file.bz2 | wc -l
# Extract specific lines to new file
bzless -N data.bz2 | grep "ERROR" > errors.txt
# View compressed files through pager
cat file_list.txt | xargs bzless
Performance Optimization
Memory Management
# For very large compressed files, use specific options
bzless -i -G huge_log.bz2
# Reduce memory usage
bzless --no-init large_file.bz2
# Optimize for slow connections
bzless -q remote_file.bz2
Search Efficiency
# Disable highlighting for faster searches
bzless -G searchable_file.bz2
# Use efficient search patterns
bzless -i log_file.bz2
# Search: /error[0-9]* - more efficient than /error.*
Troubleshooting
Common Issues
File Access Problems
# Check if file is actually bzip2 compressed
file document.txt.bz2
# Try decompressing first if bzless fails
bunzip2 -t document.txt.bz2
# View file permissions
ls -la *.bz2
Terminal Display Issues
# Reset terminal if display gets corrupted
reset
# Use different terminal settings
export LESS="-R"
bzless problem_file.bz2
# Try basic viewing mode
bzless --no-init problem_file.bz2
Memory Issues
# For low memory systems
bzless -i -G large_file.bz2
# Monitor memory usage
/usr/bin/time -v bzless huge_file.bz2
Error Resolution
Corrupted Files
# Test file integrity
bunzip2 -t corrupted_file.bz2
# Try to recover partial content
bunzip2 -c corrupted_file.bz2 | less
# Use alternative decompression
bzip2 -dc corrupted_file.bz2 | less
Related Commands
less- Standard file viewerbzip2- bzip2 compression utilitybunzip2- bzip2 decompression utilitybzcat- Concatenate bzip2 filesbzgrep- Search in bzip2 filesbzmore- Alternative bzip2 viewerzless- View gzip compressed filesxzless- View xz compressed files
Best Practices
- Use
-Nfor line numbers when debugging or referencing specific lines - Combine with search (
/pattern) for efficient log analysis - Use
-Ffor small files to quit automatically when done - Use
-efor scripts that should exit at end of file - Use
-ior-Ifor case-insensitive searching - Use
-Gfor large files to improve search performance - Set marks (
m) for quick navigation in large files - Use multiple file viewing for log rotation analysis
- Combine with pipelines for automated analysis
- Use lesskey files for custom key bindings and productivity
Performance Tips
- On-the-fly decompression makes bzless memory efficient for large files
- Search highlighting can be disabled (
-G) for better performance on huge files - Case-insensitive search (
-I) is useful for log analysis - Line numbers (
-N) are helpful but use slightly more memory - Automatic quit (
-e) is useful for scripted operations - Multiple file viewing allows efficient log rotation analysis
- Pattern matching works with full regular expressions
- Terminal optimization can improve display on slow connections
The bzless command is an essential tool for efficiently viewing bzip2-compressed text files, combining the powerful navigation features of less with seamless bzip2 decompression. Its ability to search, navigate, and analyze compressed content without full decompression makes it invaluable for system administrators, developers, and anyone working with large compressed text files or logs.