bat
Overview
bat is a modern cat replacement with syntax highlighting, git integration, line numbers, and automatic paging. Optional package on most distros (apt install bat — binary may be batcat on Debian/Ubuntu). Excellent for reading code and configs interactively; keep cat for portable scripts.
Syntax
bat [options] [file...]
batcat [options] [file...] # Debian/Ubuntu package name collisionCommon Options
| Option | Description |
|---|---|
-n, --number |
Show line numbers (often default in some themes) |
-p, --plain |
Plain mode (no decorations; closer to cat) |
-A, --show-all |
Show non-printable characters |
-l, --language |
Force language for highlighting |
-r, --line-range |
Only print a range (N:M) |
-H, --highlight-line |
Highlight a line |
-C, --context |
Context lines around highlights (with grep integration) |
--style |
Configure decorations (auto,full,plain,numbers,…) |
--theme |
Color theme |
-f, --force-colorization |
Color even when piping (careful) |
--paging=never |
Disable pager |
-d, --diff |
Show git diff modifications |
-m, --map-syntax |
Map glob → language |
Examples with Explanations
View files
bat README.md
bat /etc/ssh/sshd_config
bat src/main.rsDebian binary name
command -v bat batcat
alias bat=batcat # common convenience on Ubuntu
batcat -p file.txtPlain / script-friendly
bat -p file.txt
bat --paging=never -p file.txt | wc -lRanges and highlights
bat -r 20:40 file.go
bat -H 42 config.yaml
bat -r :50 -H 10 app.pyForce language
bat -l json mystery.conf
bat -l yaml /etc/netplan/01-netcfg.yamlMultiple files and stdin
bat *.md
command | bat -l log
curl -fsSL https://example.com/file.yaml | bat -l yamlGit-aware
bat -d src/main.rs # highlight modifications when in a git repoThemes and style
bat --list-themes
bat --theme=TwoDark file.rs
bat --style=numbers,changes file.rsAs man / pager helper
export MANPAGER="sh -c 'col -bx | bat -l man -p'"
# or use bat's own man integration if configuredCompare with cat / less
cat file.md # raw dump
bat file.md # highlight + pager
less -R file.md # pager onlyNotes / Pitfalls
- Not installed by default on servers; scripts should not require
bat. - Color in pipes can break consumers — default is usually no color when non-tty; use
-p/--paging=neverwhen unsure. - Debian renames to
batcatbecause of anotherbatpackage. - Huge minified JSON/logs: disable paging or use
less/jqfor structure. - Theme readability depends on terminal truecolor support.
2026-relevant notes
- Pairs well with
eza,fd,rg,deltaas a modern CLI toolkit. batcache/ automatic syntax detection covers most languages; force-lfor unusual extensions.- In CI, stick to
catfor deterministic plain logs.
Additional Resources
man bat/bat --help- sharkdp/bat