bat: cat with syntax highlighting, line numbers and git markers
TL;DR
bat replaces cat for reading files: syntax highlighting, line numbers, git change markers and automatic paging. Use -r for line ranges, -l for piped data, and pair it with fzf for previews.
cat prints a file to the screen, nothing more. When reading a long config file or a piece of code, you have to track lines yourself, with no colour and no idea which lines just changed. bat is "a cat clone with wings": syntax highlighting for hundreds of languages, line numbers, markers for lines changed according to git, and automatic paging for long files. When piped to another command it behaves like plain cat, so it can replace it without breaking scripts.

Installation
brew install bat # macOS
sudo apt install bat # Ubuntu/Debian: the command is batcat
cargo install --locked bat # with Rust
# On Ubuntu, add an alias
alias bat=batcat
Basic usage
bat src/main.rs # colours, line numbers, git markers
bat README.md package.json # several files in a row
bat -r 40:60 app.py # only lines 40 to 60
bat -p config.yaml # "plain": no line numbers or frame
bat -A script.sh # show hidden characters: tabs, spaces, newlines
curl -s https://api.github.com/repos/sharkdp/bat | bat -l json
The last command shows a useful trick: piped data has no file extension, so use -l to choose the language for highlighting.
Useful options
| Option | Effect |
|---|---|
--list-themes, --theme | List and pick colour themes; set a default with BAT_THEME |
--style | Choose components: numbers, changes, header, grid… |
--paging=never | Don't open a pager, print directly |
-l | Force a language for highlighting (handy for piped data) |
--diff | Only show lines changed according to git, with context |
Integrating with other tools
- Coloured man pages: add to
.zshrc:export MANPAGER="sh -c 'col -bx | bat -l man -p'". - fzf preview pane:
fzf --preview 'bat --color=always --line-range :200 {}'. - Coloured logs:
tail -f app.log | bat --paging=never -l log. - Config file: run
bat --generate-config-fileto create one and set your theme and style once.
Caveats
- Don't alias
cat=batif scripts rely on cat-specific flags; although bat switches to plain mode when piped, keep the alias for interactive use. - Colours depend on your terminal; if they look odd, try another theme or check 24-bit colour support.
- Very large files are slower than cat because of highlighting; use
-rorheadwhen you only need part of them.
How to apply it
- Dev: Use bat instead of cat when reading code in the terminal or over SSH, and
-rto jump straight to the line numbers from a stack trace. - Tech Lead: For a quick review on a server without an IDE,
bat --diffshows what changed since the last commit. - PM: Zero cost, one install command; add it to the standard toolset when setting up machines for new developers.
Sources & references
- sharkdp/bat — sharkdp (GitHub)