$linuxjunkies
>

bat(1)

A cat clone with syntax highlighting, line numbers, and git integration for viewing file contents.

UbuntuDebianFedoraArch

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

FlagWhat it does
-n, --numberDisplay line numbers
-l, --language <LANGUAGE>Force syntax highlighting for a specific language
-p, --plainDisable 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-allShow non-printable characters (spaces, tabs, newlines)
-C, --context <LINES>Include N lines of context around matches
--list-languagesList all supported languages and their file extensions
--list-themesList all available color themes

Examples

Display a Python file with syntax highlighting and line numbers

bat script.py

Show a YAML config file with explicit line numbering

bat -n config.yaml

Display only lines 10 through 20 of a JavaScript file

bat -r 10:20 app.js

Pipe content through bat and force text language syntax highlighting

cat file.txt | bat --language txt

View a Go file using the Dracula color theme

bat --theme Dracula main.go

Display a file without highlighting or line numbers (plain mode)

bat -p large-file.log

List all available color themes to choose from

bat --list-themes

Show all non-printable characters including spaces and tabs

bat -A whitespace.txt

Related commands