LinuxCommandLibrary

bat

TLDR

View file with syntax highlighting

$ bat [file.js]
copy
Show line numbers
$ bat -n [file.py]
copy
Show non-printable characters
$ bat -A [file.txt]
copy
Page output
$ bat -p [file.log]
copy
Multiple files
$ bat [file1.rs] [file2.rs]
copy
Specific language
$ bat -l [python] [script]
copy

SYNOPSIS

bat [options] [file...]

DESCRIPTION

bat is a cat clone with syntax highlighting and Git integration. It displays file contents with automatic language detection, line numbers, and Git diff indicators in the margin.
The tool provides a more user-friendly file viewing experience for developers and system administrators.

PARAMETERS

-n, --number

Show line numbers
-A, --show-all
Show non-printable characters
-p, --plain
Plain mode (no decorations)
-l, --language lang
Specify language for syntax highlighting
-H, --highlight-line n
Highlight specific lines
--paging when
When to use pager (auto, always, never)
--style components
Configure output style
--theme name
Color theme
--list-languages
List supported languages
--list-themes
List available themes

FEATURES

- Syntax highlighting for 200+ languages
- Git integration (shows modifications)
- Line numbers
- Non-printable character display
- Automatic paging
- File concatenation
- Themes support
- Integrates with less pager

CONFIGURATION

Config file: `~/.config/bat/config`

$ --theme="Monokai Extended"
--style="numbers,changes,grid"
copy

CAVEATS

Not a drop-in cat replacement for scripts (use cat for pipelines). Slower than cat on large files. Themes require true color terminal. Some syntax highlighting requires additional setup.

HISTORY

bat was created by David Peter (sharkdp) in 2018 as a modern replacement for cat with syntax highlighting and Git awareness.

SEE ALSO

cat(1), less(1), highlight(1)

Copied to clipboard