A cat command replacement with syntax highlighting and great formatting, perfect for viewing source code and Markdown files.
Overview
Bat is a modern replacement for the classic cat command that adds essential
features developers need: syntax highlighting, line numbers, and intelligent
formatting. It’s like cat but with wings.
Key Features
- Syntax Highlighting: Supports hundreds of languages and file types
- Line Numbers: Optional line numbering for code reference
- File Integration: Automatically handles git diff output and file changes
- Paging Support: Integrates with less for large files
- Theme Support: Customizable color schemes and themes
- File Type Detection: Automatic language detection based on file extension
Common Use Cases
Quick Code Viewing
# View source code with syntax highlighting
bat app.js
# View with line numbers
bat -n style.css
# View multiple files
bat *.mdEnhanced File Inspection
# Show file headers and metadata
bat --header config.json
# View git diff output
bat --diff
# Show non-printable characters
bat --show-all binary.datDevelopment Workflow Integration
# View log files with syntax highlighting
bat -l log application.log
# View configuration files
bat ~/.config/nvim/init.vim
# Quick API documentation viewing
bat --language=python api.pyWhy Developers Choose Bat
- Better readability: Syntax highlighting makes code instantly understandable
- Fast performance: Written in Rust, handles large files efficiently
- Git integration: Shows git status and changes in context
- IDE-like experience: Brings familiar code viewing to terminal
- Minimal learning curve: Drop-in replacement for cat with added benefits
Advanced Features
Custom Themes
# List available themes
bat --list-themes
# Use specific theme
bat --theme=GitHub script.js
# Create custom theme
bat --print-theme=Monokai Extended > my-theme.tmThemeOutput Control
# Output without decorations (for scripting)
bat --plain data.json
# Force specific language
bat --language=python script
# Show file information
bat --stat --line-range 50:100 large_file.goIntegration with Other Tools
Bat works seamlessly with other terminal tools:
# Pipe output to bat
ps aux | bat -l ps
# Use with find
find . -name "*.py" -exec bat {} +
# Combine with grep
grep -r "function" src/ | bat -l logResources
Bat transforms the simple act of viewing files into a rich, informative experience that makes terminal development more productive and enjoyable.