bat: A cat(1) Clone That Adds Syntax Highlighting and Git Awareness
A cat(1) clone with wings. If you are looking for more support for git and diff operations, check out delta.
At a glance
- What is it?
- bat is a Rust-based cat replacement that brings syntax highlighting, line numbers, and Git integration to the terminal. It is a practical tool for developers who read code in the shell, but its paging and auto-detection behavior require deliberate configuration.
- Who is it for?
- Adopt bat if you spend significant time reading source files in the terminal and want syntax highlighting, line numbers, and Git modification markers without leaving the shell. Skip it if you need a pure cat replacement for scripting, because bat intentionally pages output and changes behavior based on terminal detection; for that use case, stick with cat or alias bat --paging=never.
- Can I use it commercially?
- Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 11 days ago.
- What is it written in?
- Mainly Rust, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on September 14, 2026, and from our analysis. They are not legal advice.
DEEP OPEN-SOURCE ANALYSIS
What bat Solves for Terminal Readers
The core problem bat addresses is readability. Plain cat(1) dumps file contents with no visual structure, so developers who read code in the terminal often miss syntax errors or struggle to scan long files. bat adds syntax highlighting for a large number of programming and markup languages, plus line numbers and Git modification markers in the left sidebar. It is built for developers, system administrators, and anyone who regularly inspects source files, logs, or configuration files from a shell. The README positions it as a drop-in replacement for cat, but only in specific contexts: when the output is piped to another process or file, bat falls back to plain output. For interactive terminal use, it enhances readability. The project description explicitly points to delta for users who need more support for git and diff operations, which sets a clear boundary: bat is a file viewer, not a diff tool.
The Mechanism: Syntax Detection and Paging Logic
bat works by reading input and determining the syntax to highlight. For files, it likely uses the file extension and possibly content inspection. For stdin, the README states that highlighting only works if the syntax can be determined from the first line, usually through a shebang such as #!/bin/sh. That is a real constraint: piping arbitrary text into bat without a shebang yields no highlighting. The other key mechanism is automatic paging. By default, bat pipes its own output to a pager like less if the output is too large for one screen. This is a deliberate design choice to keep output readable, but it changes behavior compared to cat. The README gives a clear workaround: set --paging=never to always act like cat. When bat detects a non-interactive terminal, it prints plain file contents regardless of the pager setting. That means in scripts or pipelines, bat behaves like cat, which is useful for compatibility but can surprise users who expect colored output in a pipe.
Getting Started: Installation and Basic Commands
The README does not provide explicit installation commands, but it links to the crates.io page, indicating that bat is distributed as a Rust crate. Users can likely install it via cargo install bat, but that is not confirmed from the README. On some older Debian or Ubuntu releases, the executable is named batcat instead of bat, which is a practical note for those distributions. Basic usage is straightforward: bat README.md displays a single file. bat src/*.rs displays multiple files at once. Reading from stdin with auto-detection works only with a shebang, as in curl -s https://sh.rustup.rs | bat. To specify the language explicitly, use -l, for example yaml2json.travis.yml | json_pp | bat -l json. For non-printable characters, use -A or --show-all, as in bat -A /etc/hosts. The README also shows concatenation: bat header.md content.md footer.md > document.md, and bat f - g to output file f, then stdin, then file g. These commands cover the core use cases.
Configuration: Paging, Aliases, and the Config File
The README emphasizes that bat reads options from a configuration file, but it does not show the file path or format. It does state that you can set --paging=never either on the command line or in your configuration file. That is a concrete config key. For users who want to alias cat to bat, the README suggests alias cat='bat --paging=never' to preserve the default cat behavior. This is important because without that flag, bat pages output, which can break scripts or interactive habits. The README also shows how to use bat as a colorizing pager for man pages by setting MANPAGER="bat -plman". That is a specific environment variable and flag combination. For help text highlighting, you can alias bathelp='bat --plain --language=help' and define a shell function to pipe command help through it. These examples show that bat is designed to be customized heavily, but the documentation leaves the config file location implicit, which is a gap for new users.
Integration Patterns: fzf, git, and tail -f
The README documents several integrations that make bat useful beyond simple file viewing. For fzf, you can use bat as a previewer with fzf --preview "bat --color=always --style=numbers --line-range=:500 {}". The --color=always flag forces colorized output even in a pipe, and --line-range restricts load times for long files. For git, you can combine bat with git show to view an older version of a file: git show v0.6.0:src/main.rs | bat -l rs. For git diff, the README provides a shell function batdiff that uses git diff --name-only and pipes to bat --diff. That is a specific flag, --diff, which presumably shows Git modification markers. For tail -f, the README warns that you must switch off paging and specify the syntax explicitly: tail -f /var/log/pacman.log | bat --paging=never -l log. These integrations show that bat is not just a cat replacement but a building block for custom terminal workflows. The fzf integration is particularly practical for file previews, and the --line-range option is a thoughtful addition for performance.
Limitations: Stdin Detection, Paging Surprises, and Diff Scope
The most concrete limitation is stdin syntax detection. The README states that highlighting only works if the syntax can be determined from the first line, usually through a shebang. That means piping a log file or a config snippet without a shebang will produce no highlighting unless you specify -l explicitly. This is a real friction point for a tool that promises syntax highlighting. Another limitation is the paging behavior. By default, bat pages output, which can be annoying in scripts or when you just want to see a short file. The README provides the --paging=never workaround, but it is an extra flag to remember. Also, the non-interactive terminal detection means that piping bat output to another command strips the highlighting, which is correct for compatibility but can be surprising if you want to preserve colors in a pipeline. Finally, bat is not a diff tool. The README explicitly points to delta for more support for git and diff operations. bat has a --diff flag for showing modifications, but it is not a full diff viewer. For complex diff workflows, delta is the intended alternative.
Alternatives: delta and the bat-extras Ecosystem
The README names delta as the alternative for users who need more support for git and diff operations. delta is a separate project that focuses on rendering git diffs with syntax highlighting and a side-by-side view. The key difference is that delta is built for diff output, not for viewing individual files. bat is a general-purpose file viewer that happens to show Git modification markers in the sidebar. If your primary need is reading diffs, delta is the better fit because it is designed for that input stream. The README also mentions bat-extras, a collection of scripts that extend bat, including batgrep for ripgrep integration, batdiff for a dedicated diff tool, and batman for man pages. These scripts wrap bat to provide more specialized commands. The existence of bat-extras is a sign that bat itself is intentionally minimal, and users who want more features must install additional scripts. This is a trade-off: bat stays focused, but you have to assemble your own toolchain.
Maintenance, License, and Upgrade Considerations
bat is written in Rust and licensed under Apache-2.0, which is permissive for commercial use. The repository is not archived, and the last push was December 2, 2025, with version v0.26.1 released on the same date. The release history shows a steady cadence: v0.26.0 in October 2025 and v0.25.0 in January 2025. That suggests active maintenance. However, the README does not document an upgrade path or migration notes. Users should check the release notes for each version, especially for changes to default behavior like paging or syntax detection. The project is a single binary, so upgrading likely means replacing the executable, but the README does not specify. The config file format is not documented in the README, so upgrading could change options silently if the format evolves. The maintenance cost is low for users, but the documentation gap around configuration is a minor concern. The project has a clear scope, and the README points to delta for diff-specific needs, which reduces feature creep.
Editorial conclusion
Adopt bat if you spend significant time reading source files in the terminal and want syntax highlighting, line numbers, and Git modification markers without leaving the shell. Skip it if you need a pure cat replacement for scripting, because bat intentionally pages output and changes behavior based on terminal detection; for that use case, stick with cat or alias bat --paging=never. Before adopting, verify that your terminal supports the color schemes you want and that the syntax auto-detection works for your file types, since stdin highlighting only works when the first line contains a shebang. Also check the latest release notes for v0.26.1 to see any changes to paging or configuration defaults.
Community notes