bat(1)
A cat clone with syntax highlighting, line numbers, and git integration for viewing file contents.
Synopsis
bat [OPTIONS] [FILE]...Description
bat is a syntax-highlighted replacement for cat that displays file contents with line numbers, git modifications, and automatic paging. It detects file types and applies appropriate syntax highlighting, making it ideal for reading code and configuration files in the terminal.
When no file is specified or when reading from stdin, bat displays the input with syntax highlighting. It integrates with git to show which lines have been added, modified, or deleted since the last commit.
Common options
| Flag | What it does |
|---|---|
-n, --number | Display line numbers |
-l, --language <LANGUAGE> | Force syntax highlighting for a specific language |
-p, --plain | Disable syntax highlighting and line numbers; equivalent to cat |
-t, --tabs <TAB_WIDTH> | Set the tab width (default: 4) |
--theme <THEME> | Set the color theme (e.g., Dracula, GitHub, Monokai) |
--style <COMPONENTS> | Control output style: full, plain, header, grid, or snip |
-r, --line-range <N:M> | Only print lines N to M (e.g., 5:20) |
-H, --highlight-line <N> | Highlight a specific line number |
-A, --show-all | Show non-printable characters (spaces, tabs, newlines) |
-C, --context <LINES> | Include N lines of context around matches |
--list-languages | List all supported languages and their file extensions |
--list-themes | List all available color themes |
Examples
Display a Python file with syntax highlighting and line numbers
bat script.pyShow a YAML config file with explicit line numbering
bat -n config.yamlDisplay only lines 10 through 20 of a JavaScript file
bat -r 10:20 app.jsPipe content through bat and force text language syntax highlighting
cat file.txt | bat --language txtView a Go file using the Dracula color theme
bat --theme Dracula main.goDisplay a file without highlighting or line numbers (plain mode)
bat -p large-file.logList all available color themes to choose from
bat --list-themesShow all non-printable characters including spaces and tabs
bat -A whitespace.txt