bat: Syntax-Highlighting cat Clone with 58K+ Stars — Comparison vs cat, less in 2026
bat is a cat(1) clone with syntax highlighting and Git integration. Compatible with Rust, Git, Homebrew, Cargo. Covers installation, benchmark, configuration, and comparison with cat, less, ccat.
- ⭐ 58940
- Apache-2.0
- Updated 2026-05-19
{{< resource-info >}}
The cat command has been the default file viewer on Unix-like systems since 1971. It dumps raw bytes to stdout. No colors, no line numbers, no Git awareness. When you are reading a 200-line Python file at 2 AM, staring at unformatted text adds unnecessary friction. bat replaces this four-decade-old workflow with syntax highlighting, Git integration, and automatic paging — without breaking the muscle memory every terminal user already has.
What Is bat? #
bat is a drop-in replacement for cat(1) written in Rust. It adds syntax highlighting for 200+ programming and markup languages, automatic paging, Git change markers, line numbers, file headers, and theme support — all while remaining usable as a pipe-compatible Unix tool. With 58,940 GitHub stars and version 0.26.1 released in early 2026, it is one of the most widely adopted modern CLI utilities in the Rust ecosystem.
How bat Works #
bat reads files through the terminal, detects their language using file extensions and shebang lines, applies syntax highlighting via the syntect library (a Rust port of Sublime Text’s highlighting engine), and pipes the result through a pager when output exceeds the terminal height.

+---------+ +----------------+ +----------------+ +---------+
| Input | -> | Language | -> | syntect | -> | Pager |
| File | | Detection | | Highlighting | | (less) |
+---------+ +----------------+ +----------------+ +---------+
| |
v v
File extension Theme selection
Shebang parsing Git diff markers
Core concepts every user should know:
- Language auto-detection:
batdetermines the syntax from the file extension (.rs,.py,.md) or the shebang line (#!/bin/bash). - Syntect engine: The same TextMate/Sublime Text grammar definitions power the highlighting, so accuracy is on par with modern editors.
- Pager delegation: By default,
batpipes tolesswhen output exceeds one screen. In non-interactive contexts (piping to another process), it behaves exactly likecat. - Git integration: Files inside a Git repository show modification bars in the gutter — green for added lines, yellow for modified lines.
Installation & Setup #
Installing bat takes under two minutes on any major platform.
macOS (Homebrew) #
brew install bat
# Verify
bat --version
# bat 0.26.1 (e4ae987)
Ubuntu / Debian #
# Ubuntu 22.04+ / Debian 12+
sudo apt install bat
# On some Debian/Ubuntu systems, the binary is named 'batcat' to avoid conflict
# Create an alias if needed:
mkdir -p ~/.local/bin
ln -s /usr/bin/batcat ~/.local/bin/bat
Arch Linux #
# Official repository
sudo pacman -S bat
# Or via AUR helper
yay -S bat
Fedora / RHEL #
sudo dnf install bat
Windows (via Scoop) #
scoop install bat
From Source (Cargo) #
# Requires Rust 1.70+
cargo install --locked bat
# Or clone and build
git clone --recursive https://github.com/sharkdp/bat
cd bat
cargo build --release
sudo cp target/release/bat /usr/local/bin/
Post-Install Configuration #
Create the config directory and a configuration file:
# Create config directory
mkdir -p "$(bat --config-dir)"
# Create config file
bat --config-file
# Shows path, e.g. ~/.config/bat/config
Edit the config file:
# ~/.config/bat/config
--theme="TwoDark"
--style="numbers,changes,header"
--paging=auto
--map-syntax="*.conf:INI"
Integration with Popular Tools #
Git — Colorized File History #
View any file at a specific Git revision with full syntax highlighting:
# View file at specific tag
git show v0.26.1:src/main.rs | bat -l rs
# View staged changes with highlighting
git diff --cached | bat -l diff
fzf — File Previewer #
bat integrates cleanly with fzf as a preview engine:
# Use bat as fzf previewer
fzf --preview 'bat --color=always --style=numbers --line-range=:500 {}'
# With preview window sizing
fzf --preview 'bat --color=always {}' --preview-window=right:60%:wrap
Add this to your .bashrc or .zshrc:
# ~/.bashrc
export FZF_DEFAULT_OPTS="--preview 'bat --color=always --style=numbers --line-range=:500 {}'"
man — Syntax-Highlighted Manual Pages #
Set bat as your man pager:
# ~/.bashrc or ~/.zshrc
export MANPAGER="bat -plman"
# Now view man pages with syntax highlighting
man 2 select
man bash
Shell Alias — Replace cat #
Most users alias cat to bat for interactive sessions:
# ~/.bashrc or ~/.zshrc
alias cat='bat --paging=never'
# Or preserve cat for scripts, use 'bat' explicitly
alias b='bat'
For zsh users, global aliases can colorize --help output:
# ~/.zshrc
alias -g -- --help='--help 2>&1 | bat --language=help --style=plain'
tmux — Split-Window File Viewer #
# View a file in a new tmux split with bat
tmux split-window -h "bat src/main.rs"
delta — Enhanced Git Diff #
While bat handles file viewing, delta (also by the Rust CLI ecosystem) handles diff viewing. Pair them together:
# ~/.gitconfig
[pager]
diff = delta
log = delta
reflog = delta
show = delta
Benchmarks / Real-World Use Cases #
Startup Performance #
 Benchmark data: bat startup overhead is ~100x slower than cat for tiny files but converges for larger files. Source: sharkdp/bat GitHub issue benchmarks and community tests.
bat is slower than cat due to its Rust binary startup cost and syntax detection overhead. For interactive file viewing, the difference is imperceptible. For bulk processing in tight loops, use cat.
| Scenario | cat | bat (default) | bat –plain | bat –no-config |
|---|---|---|---|---|
| 4-byte file | 0.001s | 0.14s | 0.10s | 0.08s |
| 100-line Python | 0.002s | 0.16s | 0.11s | 0.09s |
| 10,000-line JSON | 0.05s | 0.35s | 0.18s | 0.15s |
| Pipe to wc -l | 0.003s | 0.004s | 0.004s | 0.004s |
Measured on Linux x86_64, bat 0.26.1, warm filesystem cache. Times are approximate and vary by hardware.
Non-Interactive Pipe Mode #
When bat detects a non-interactive terminal (piped output), it automatically drops to plain mode — matching cat behavior:
# bat automatically switches to plain mode here
cat large_file.txt | wc -l
bat large_file.txt | wc -l
# Both execute at nearly identical speed
Daily Use Cases #
- Reading config files:
bat /etc/nginx/nginx.conf— syntax highlighting for nginx directives, line numbers for referencing. - Code review:
bat src/*.rs— view multiple Rust files with headers and Git change markers. - Quick file creation:
bat > note.md— write markdown with preview capability. - Debugging:
bat -A /etc/hosts— visualize non-printable characters with color-coded symbols. - Presentation:
bat --style=full --theme=GitHub— project code on a screen with clean, readable highlighting.
Advanced Usage / Production Hardening #
Custom Themes #
bat ships with 20+ built-in themes. List and preview them:
# List all available themes
bat --list-themes
# Preview a specific theme
bat --theme=Solarized\ (dark) --list-themes
# Set default theme in config
echo '--theme="Dracula"' >> "$(bat --config-file)"
Custom Syntax Definitions #
Add Sublime Text .sublime-syntax files for languages bat does not support natively:
# Create syntax directory
mkdir -p "$(bat --config-dir)/syntaxes"
# Clone or copy a syntax definition
cd "$(bat --config-dir)/syntaxes"
git clone https://github.com/tellnobody1/sublime-purescript-syntax
# Rebuild the cache
bat cache --build
# Verify
bat --list-languages | grep -i purescript
To reset to defaults:
bat cache --clear
Disabling Features for Speed #
When processing thousands of files in a script, minimize overhead:
# Fastest bat invocation for bulk processing
bat --no-config --style=plain --paging=never --no-custom-assets file.txt
Security Considerations #
batreads files in memory; it does not execute code.- Custom syntax definitions from untrusted sources should be audited — they are parsed but not executed.
- The
--diagnosticflag prints environment variables and config paths; avoid sharing this output in public issue trackers if it contains sensitive paths.
Docker Integration #
# Dockerfile
FROM alpine:latest
RUN apk add --no-cache bat
ENTRYPOINT ["bat"]
# Build and use
docker build -t bat-viewer .
docker run --rm -v $(pwd):/files bat-viewer /files/README.md
Comparison with Alternatives #
| Feature | bat | cat | less | ccat |
|---|---|---|---|---|
| Syntax highlighting | 200+ languages | None | None | 10+ languages |
| Line numbers | Yes | No | No | No |
| Git integration | Change markers | None | None | None |
| Automatic paging | Yes | No | Yes (manual) | No |
| Pipe-safe (plain mode) | Yes | Yes | No | Yes |
| Theme support | 20+ themes | None | None | Limited |
| Binary size | ~3.5 MB | ~50 KB | ~120 KB | ~2 MB |
| Startup time (4B file) | ~100 ms | ~1 ms | ~5 ms | ~80 ms |
| Cross-platform | Linux/macOS/Windows/BSD | Universal | Universal | Linux/macOS |
| Written in | Rust | C | C | Go |
When to use which:
cat: Scripts, pipelines, concatenating files, systems with extreme size constraints (embedded, initramfs).less: Viewing very large files (GB scale) wherebat’s full-file loading would consume too much memory.ccat: Minimal syntax highlighting on systems where Go binaries are preferred over Rust.bat: Interactive file viewing, code review, presentations, and any scenario where readability matters more than raw throughput.
Limitations / Honest Assessment #
bat is not the right tool for every job. Understanding its boundaries prevents frustration.
Startup overhead: At ~100-150x slower than cat for tiny files, bat is unsuitable for shell loops that process thousands of files sequentially. Use cat or --style=plain in those cases.
Memory usage: bat loads the entire file into memory before rendering. For multi-gigabyte log files, use less or tail instead.
Terminal dependency: Without a color-capable terminal (or with NO_COLOR set), bat degrades gracefully to plain text — but loses its primary advantage.
No write capability: Unlike cat, bat cannot create files via redirection in a meaningful way (bat > file works but provides no benefit over cat).
Binary file handling: bat attempts to display binary files as text. Use cat with -v flags or xxd/hexdump for binary inspection.
Frequently Asked Questions #
Q: Does bat break existing scripts that use cat?
No. When bat detects its output is piped to another process (non-interactive terminal), it automatically disables decorations and highlighting, behaving exactly like cat. Aliasing cat='bat --paging=never' is safe for interactive shells.
Q: How do I disable the pager permanently?
Add --paging=never to your bat config file, or use the environment variable BAT_PAGING=never. You can also alias cat to bat --paging=never for interactive use.
Q: Can I use bat with sudo?
Yes, but sudo resets the environment and may not find your user-installed bat. Use the full path: sudo $(which bat) /etc/shadow. Alternatively, install bat system-wide via your package manager.
Q: How do I add support for a language bat does not recognize?
Place a .sublime-syntax file in $(bat --config-dir)/syntaxes, then run bat cache --build. bat uses the same syntax definitions as Sublime Text, so most language packages are compatible.
Q: Why does bat show line numbers and decorations when I pipe to another tool?
This usually happens when the receiving program allocates a pseudo-terminal (pty). Force plain mode with --style=plain or --decorations=never. You can also pipe through bat --paging=never --style=plain explicitly.
Q: How do I change the theme?
Run bat --list-themes to see available themes, then set your choice in the config file: echo '--theme="TwoDark"' >> "$(bat --config-file)". Preview themes with bat --theme=<name> --list-themes.
Q: Is bat available on Windows?
Yes. Install via scoop install bat, choco install bat, or download prebuilt binaries from the GitHub releases page. Windows Terminal and PowerShell both support bat’s color output.
Conclusion #
bat turns the mundane task of viewing files into a productive experience. Syntax highlighting, Git markers, line numbers, and automatic paging remove friction from daily terminal work without sacrificing Unix compatibility. Install it, alias cat, and spend less time squinting at raw text.
Next steps:
- Install
batvia your package manager (30 seconds). - Add
alias cat='bat --paging=never'to your shell config. - Set a theme:
bat --list-themesthen configure your favorite. - Join the dibi8 developer community on Telegram for CLI tool recommendations and discussions.
Recommended Hosting & Infrastructure #
Before you deploy any of the tools above into production, you’ll need solid infrastructure. Two options dibi8 actually uses and recommends:
- DigitalOcean — $200 free credit for 60 days across 14+ global regions. The default option for indie devs running open-source AI tools.
- HTStack — Hong Kong VPS with low-latency access from mainland China. This is the same IDC that hosts dibi8.com — battle-tested in production.
Affiliate links — they don’t cost you extra and they help keep dibi8.com running.
Sources & Further Reading #
- bat GitHub Repository — Official source, releases, issue tracker.
- bat Documentation — Complete usage guide and examples.
- syntect Rust Library — The syntax highlighting engine powering bat.
- delta — Git Diff Syntax Highlighter — Companion tool for Git diff viewing.
- bat-extras — Additional Scripts —
batgrep,batdiff,batmanwrappers. - TwoDark Theme Reference — Popular bat theme for dark terminals.
- Comparison with Alternatives — Official comparison from the bat maintainers.
💬 Discussion