sharkdp / bat
bat turns reading a file in the terminal into a deliberate interface
sharkdp/bat adds syntax highlighting, Git change markers, line numbers, paging, themes, and visible control characters to the familiar act of printing a file. It is a small tool with thoughtful terminal behavior, especially when kept out of scripts that require cat's portability and byte-oriented simplicity.
WHAT TO KNOW FIRST
- bat is designed for human-readable file display, combining syntax highlighting, Git-aware change indicators, line numbers, and paging according to terminal context.
- Styles, colors, paging, wrapping, tabs, and non-printable characters are configurable, so automation should set the required output behavior instead of parsing a personal display.
- The project is offered under Apache-2.0 or MIT at the user's option, and its bundled syntax definitions, themes, and release artifacts still deserve notice review when redistributed.
01A familiar verb with a different audience
bat calls itself a cat clone with wings, but its central audience is a person looking at a file. It adds syntax-aware color, line numbers, a header, Git modification markers, and a pager when output would exceed the terminal. The command remains simple enough to type from memory, while the display answers questions that usually require opening an editor: what language is this, where am I, and which lines changed?
That focus explains why bat should complement rather than universally replace cat. cat is a basic byte-stream utility found across Unix environments and used heavily in pipelines. bat applies presentation policy that varies with terminal detection and options. An alias can improve interactive work, but scripts and recovery instructions should call the exact tool whose output contract they require.
02Syntax highlighting is useful context, not parsing
bat uses syntax definitions and themes to color many programming and markup languages. It normally infers syntax from the file name or extension, and users can select a language explicitly when inference is unavailable or input comes from standard input. Highlighting makes comments, strings, keys, headings, and control structures easier to scan, especially in an unfamiliar configuration file.
A highlighter is not a compiler or validator. Malformed input, embedded languages, unusual extensions, and new syntax can color imperfectly while the file remains unchanged. Never treat color as proof that a configuration parses or a string is safe. Pair bat with the language's formatter, parser, linter, or validation command. For raw logs and data, plain output may communicate more accurately than an incorrect syntax guess.
03Git markers add local change awareness
When a file belongs to a Git repository, bat can show changes relative to the index in a side column. Added, modified, and removed regions become visible beside the text. This is useful during review of a configuration or source file because local edits no longer hide inside an otherwise polished listing. It also helps explain why a file on one machine differs from the committed version.
The marker is not a replacement for git diff. It does not provide the full patch, staging state, rename context, commit history, or comparison against an arbitrary revision. Use it as a prompt to inspect the real diff before committing or diagnosing a deployment. Files outside Git or unsupported repository situations will not have that context. A clean gutter proves little about generated or untracked inputs.
04Paging follows the shape of the terminal
Long output is difficult to read when it races past a terminal. bat can invoke a pager under documented conditions and integrates its styling with that experience. Short output can print directly, while long files become scrollable without manually piping to less. Line wrapping, tab width, terminal width, and pager options all influence the final view.
Automation should never depend on an inferred pager. Use --paging=never or the corresponding explicit setting when a command must finish without an interactive program. Conversely, force paging only in a context that has a terminal. Test command wrappers in CI, redirected output, editor terminals, and remote shells. A hanging job that waits for pager input is an integration error, not a mysterious bat failure.
05Styles let one command serve several reading modes
The --style option controls components such as headers, file names, grid lines, rule lines, line numbers, and change markers through documented presets or combinations. --plain removes decorative elements for a simpler display. --show-all exposes non-printable characters, which can reveal tabs, line endings, or whitespace involved in a parsing problem. Range options can focus attention on selected lines without editing the source.
Presentation can become noise if every feature is enabled by default. Choose a restrained personal style and use explicit flags when sharing a diagnostic command. If exact whitespace matters, confirm behavior with a byte-oriented tool as well. Color and Unicode glyphs depend on terminal support. Logs copied into an issue should usually disable color unless the destination preserves and benefits from it.
06Pipes are supported, but output intent must be stated
bat can read standard input and can send output to another program. It detects whether output is a terminal and adjusts decoration, color, and paging accordingly. This makes commands such as generating text and viewing it interactively convenient. It also means the same invocation may look different when redirected, which is desirable for humans but unsuitable as an undocumented machine format.
For pipelines, decide whether bat is adding syntax-colored presentation or merely standing in for cat. If downstream code expects original bytes, use the simpler primitive. If a report intentionally includes ANSI color, force and document it, then test the consumer. File names can be provided alongside standard input where documented to improve syntax detection, but that label should not be mistaken for provenance of the data itself.
07Themes and syntax caches make customization tangible
Users can list available themes, choose one, and add compatible syntax definitions or themes through bat's configuration and cache directories. The repository documents how to rebuild the cache after adding assets. This supports organizations with a custom language or individuals who need contrast suited to a terminal theme. Preview a theme against several languages and diff markers rather than judging one screenshot.
Custom assets become another versioned dependency. A theme may produce unreadable combinations in light, dark, or high-contrast terminals, and a syntax definition can conflict with file detection. Keep a backup and know how to clear or rebuild the cache. Team instructions should distinguish optional display assets from requirements for running a project. A source repository should not silently modify a user's global bat configuration.
08Configuration is best kept personal and small
bat exposes the active configuration file path and supports default options through that file. A user might select a theme, style, pager policy, or tab width there. Environment variables and command-line flags can also affect behavior. This is appropriate for interactive preference, but it reduces reproducibility when a copied command depends on defaults the recipient cannot see.
Scripts should override correctness-related behavior explicitly or avoid bat. Diagnostic documentation should mention if a personal configuration may change the output and can be bypassed. When troubleshooting, compare the same file with an empty configuration, --plain, and no paging. A minimal config makes upgrades easier because fewer historical flags can collide with changed defaults or renamed themes.
09Installation details vary more than the command
The project documents prebuilt release archives and package-manager options across operating systems. Some Debian-family distributions install the binary under the name batcat because of a package-name conflict, a detail worth including in onboarding. Windows builds may require the Visual C++ Redistributable as documented. Building from source uses Rust and does not necessarily install every generated artifact in the same way as a packaged release.
Pin versions in managed environments and verify release artifacts according to organizational policy. An interactive tool can still be part of a supply chain and can process untrusted files through highlighters and terminal output. Keep bat updated, avoid displaying secrets in screen shares or logs, and use terminal controls that limit unsafe escape handling. The tool reads files with the user's permissions; attractive output does not create an access boundary.
10Use bat when reading is the task
bat is at its best in code review, incident response, onboarding, and daily navigation, where a person wants immediate structure and context. It pairs naturally with ripgrep, file selectors, Git commands, and editor launchers. A search can identify the right path and line, while bat presents the surrounding file without opening a full editor. That is a small interaction repeated often enough to matter.
Keep cat for portable scripts, exact streaming, binary concatenation, and minimal systems. Keep git diff for complete change review and a language parser for correctness. With those boundaries intact, bat does not need to replace a standard to justify itself. It turns a common terminal pause into a readable interface, and it does so through a focused, inspectable Rust repository with clear dual-license terms.
A SENSIBLE FIRST HOUR
Start small enough to learn the repo
- Install bat from an official release or documented package source, confirm bat --version, and note that some distributions name the executable batcat.
- Open a tracked source file with bat, then compare bat --plain and bat --show-all to understand decoration and non-printable character handling.
- Modify a tracked line and inspect the Git markers, then test --paging=never and piped output so scripts do not depend on an interactive pager.
- List themes and configuration paths with documented commands, create a minimal personal config, and keep project automation explicit instead of inheriting that config.
SOURCE LEDGER
What this review is built on
We use the project repository and first-party documentation. Access, licenses and project direction can change, so recheck the linked source before making a production decision.