bat — A cat Clone with Wings and Syntax Highlighting
bat is a cat clone with wings — syntax highlighting, Git integration, automatic paging, and line numbers. A drop-in replacement for cat that shows code and configs beautifully in your terminal. Written in Rust.
What it is
bat is a command-line tool that serves as a drop-in replacement for the Unix cat command. It adds syntax highlighting for over 200 languages, Git integration (showing modified lines), automatic paging, line numbers, and theme support. Written in Rust, it is fast and has no runtime dependencies beyond the binary.
bat targets developers, sysadmins, and anyone who reads code or configuration files in the terminal. If you use cat to view files, bat makes the output immediately more readable.
How it saves time or tokens
Reading raw file output in the terminal without syntax highlighting means mentally parsing code structure. bat adds color-coded syntax, line numbers, and Git change markers automatically. For reviewing configuration files, log snippets, or code during debugging, this visual structure reduces the time to understand what you are looking at. It integrates with tools like fzf, ripgrep, and man for enhanced workflows.
How to use
- Install bat:
brew install bat # macOS
sudo apt install bat # Debian/Ubuntu (may be batcat)
cargo install bat # From source
- Use it like cat:
bat file.py # View with highlighting
bat src/*.rs # Multiple files
bat -A config.yml # Show non-printable characters
- Optionally alias cat to bat in your shell config.
Example
# View a Python file with syntax highlighting
bat app.py
# Show only specific line range
bat --line-range 10:20 main.go
# Use as a pager for other tools
export MANPAGER="sh -c 'col -bx | bat -l man -p'"
git diff | bat
# Combine with ripgrep for highlighted search results
rg --json 'TODO' | bat --language json
# List available themes
bat --list-themes
Related on TokRepo
- Coding Tools -- Developer tools for code reading and writing
- Featured Workflows -- Discover popular developer tools
Common pitfalls
- On Debian/Ubuntu, the package may install as
batcatdue to a naming conflict. Create an alias:alias bat=batcat. - bat uses a pager by default (less). For piping output to other commands, use
bat --paging=neverorbat -pto get plain output. - Custom themes need to be placed in the bat config directory and rebuilt with
bat cache --build. Themes from VS Code can be converted.
Frequently Asked Questions
For interactive use, yes. bat handles all cat functionality plus adds highlighting and paging. For scripting and piping, use bat -pp (plain mode, no paging) to get behavior identical to cat.
bat is written in Rust and handles large files efficiently. For very large files (hundreds of MB), syntax highlighting adds some overhead. Use bat -p for plain mode on huge files.
bat supports over 200 languages and file formats for syntax highlighting out of the box. You can add custom syntax definitions using the Sublime Text syntax format.
Yes. bat shows Git modifications in the gutter: additions, deletions, and changes are marked with colored symbols next to line numbers. This works automatically in any Git repository.
Yes. bat ships with several themes and supports custom themes. Run bat --list-themes to see available themes. Set a default with the BAT_THEME environment variable or in the bat config file.
Citations (3)
- bat GitHub— cat clone with syntax highlighting written in Rust
- bat Documentation— 200+ supported languages
- Rust CLI Working Group— Rust command-line tools ecosystem
Related on TokRepo
Discussion
Related Assets
Conda — Cross-Platform Package and Environment Manager
Install, update, and manage packages and isolated environments for Python, R, C/C++, and hundreds of other languages from a single tool.
Sphinx — Python Documentation Generator
Generate professional documentation from reStructuredText and Markdown with cross-references, API autodoc, and multiple output formats.
Neutralinojs — Lightweight Cross-Platform Desktop Apps
Build desktop applications with HTML, CSS, and JavaScript using a tiny native runtime instead of bundling Chromium.