LinuxCommandLibrary

batcat

View file contents with syntax highlighting

TLDR

View documentation for the original command

$ tldr bat
copy

SYNOPSIS

bat [options] [file...]
bat < stdin
command | bat

PARAMETERS

-A, --show-all
    Show non-printable characters.

-l, --language <LANGUAGE>
    Explicitly set the language for syntax highlighting (e.g., -l rust).

-p, --plain
    Disable Git integration, line numbers, and decorations. Useful for raw output or scripting.

-n, --no-numbers
    Do not print line numbers.

-H, --highlight-line <LINES>
    Highlight specific lines (e.g., -H 10-20,35).

-r, --line-range <RANGES>
    Print only a specific range of lines (e.g., -r 1:10, -r :20, -r 30:).

--theme <THEME>
    Specify the color theme to use. Use --list-themes to see available options.

--list-themes
    List all available color themes.

--style <COMPONENTS>
    Set which elements of the output to display (e.g., numbers,changes,header,grid). Options: auto,full,plain,numbers,changes,header,grid,snip.

--wrap <MODE>
    Set line wrapping mode. Options: auto,always,never.

-P, --no-paging
    Disable automatic paging. Output will go directly to standard output.

--pager <COMMAND>
    Specify an external pager command (e.g., --pager 'less -RFX').

--tabs <N>
    Set the tab width to N spaces.

--map-syntax <GLOB:SYNTAX>
    Map a glob pattern to a specific syntax (e.g., --map-syntax '*.vue:html').

--config-file <FILE>
    Specify a custom configuration file.

--diagnostic
    Show diagnostic information (version, configuration, loaded syntaxes, themes).

-v, --version
    Print version information.

-h, --help
    Print help information.

DESCRIPTION

bat, often informally referred to as batcat, is a feature-rich command-line utility designed to display file contents. It serves as a modern, user-friendly alternative to the traditional cat command, enhancing its capabilities with several key features. Written in Rust, bat automatically provides syntax highlighting for a vast array of programming languages and markup formats, making code and configuration files significantly more readable. It also integrates seamlessly with Git, displaying inline modifications (additions, deletions, changes) directly in the output, similar to diff. Other notable features include automatic paging (piping output to a pager like less when content exceeds screen height), line numbering, and the ability to customize themes and styles. It's an essential tool for developers and system administrators who frequently inspect file contents in the terminal.

CAVEATS

The term batcat is an informal alias; the actual command name is bat. bat is not installed by default on most Linux distributions and needs to be installed separately. While highly useful for viewing, it's generally not recommended for scripting where raw, unformatted file content is strictly required, as its output includes syntax highlighting and other decorations. For such cases, use cat or bat --plain.

CONFIGURATION FILE

bat can be extensively configured via a configuration file, typically located at ~/.config/bat/config or specified via the --config-file option. This file allows setting default options, aliases, and custom syntax mappings, enabling a personalized viewing experience.

ENVIRONMENT VARIABLES

Several environment variables can influence bat's behavior, including BAT_THEME (to set the default theme), BAT_PAGER (to specify the pager command, overriding the default), and PAGER (fallback pager). These provide flexible ways to customize its operation without command-line arguments.

EXTENSIBILITY

bat supports adding custom syntaxes and themes, which can be useful for niche languages or specific aesthetic preferences. These can be placed in the ~/.config/bat/syntaxes and ~/.config/bat/themes directories, respectively, allowing users to extend bat's capabilities beyond its built-in set.

HISTORY

bat was created by Pascal Hertrich (@sharkdp) and first released in 2018. Developed in Rust, it quickly gained traction in the developer community as a powerful and aesthetically pleasing replacement for the traditional cat utility. Its rapid adoption stems from its out-of-the-box syntax highlighting, Git integration, and smart paging capabilities, addressing common pain points when viewing code and text files in the terminal.

SEE ALSO

cat(1), less(1), more(1), grep(1), diff(1)

Copied to clipboard