BAT(1)
π NAME π
bat β a cat(1) clone with syntax highlighting and Git integration. Thatβs the whole vibe, bestie. π¦
β¨ USAGE β¨
bat [OPTIONS] [FILE]...
bat cache [CACHE-OPTIONS] [--build|--clear]
πΈ DESCRIPTION πΈ
Okay so bat prints the syntax-highlighted content of a collection of FILEs to the terminal. If no FILE is specified, or when FILE is '-', it reads from standard input. Iconic behavior, honestly. π
bat supports a large number of programming and markup languages. It also communicates with git(1) to show modifications with respect to the Git index. And yes, bat automatically pipes its output through a pager (by default: less). Slay. π
Whenever the output of bat goes to a non-interactive terminal, i.e. when the output is piped into another process or into a file, bat will act as a drop-in replacement for cat(1) and fall back to printing the plain file contents, unless an explicit style is requested. No cap. β¨
π§ OPTIONS π§
π General remarks π
Command-line options like -l/--language that take values can be specified as either --language value, --language=value, -l value or -lvalue. Pick your fighter. π
-A,--show-allβ Show non-printable characters like space, tab or newline. Use--tabsto control the width of the tab-placeholders.--nonprintable-notation <notation>β Specify how to display non-printable characters when using--show-all.caretβ Use character sequences like^G,^J,^@,..to identify non-printable characters.unicodeβ Use special Unicode code points to identify non-printable characters.
--binary <behavior>β How to treat binary content.no-printingβ Do not print any binary content (default).as-textβ Treat binary content as normal text.
--completion <SHELL>β Show shell completion for a certain shell. Possible values:bash,fish,zsh,ps1.-p,--plainβ Only show plain style, no decorations. This is an alias for--style=plain. When-pis used twice (-pp), it also disables automatic paging (alias for--style=plain --paging=never).-l,--language <language>β Explicitly set the language for syntax highlighting. The language can be specified as a name (likeC++orLaTeX) or possible file extension (likecpp,hppormd). Use--list-languagesto show all supported language names and file extensions.-H,--highlight-line <N:M>...β Highlight the specified line ranges with a different background color. For example:--highlight-line 40β highlights line 40--highlight-line 30:40β highlights lines 30 to 40--highlight-line :40β highlights lines 1 to 40--highlight-line 40:β highlights lines 40 to the end of the file--highlight-line 30:+10β highlights lines 30 to 40
--file-name <name>...β Specify the name to display for a file. Useful when piping data tobatfromSTDINwhenbatdoes not otherwise know the filename. Note that the provided file name is also used for syntax detection.-d,--diffβ Only show lines that have been added/removed/modified with respect to the Git index. Use--diff-context=Nto control how much context you want to see.--diff-context <N>...β IncludeNlines of context around added/removed/modified lines when using--diff.--tabs <T>β Set the tab width toTspaces. Use a width of0to pass tabs through directly.--wrap <mode>β Specify the text-wrapping mode (auto,never,character). The--terminal-widthoption can be used in addition to control the output width.-S,--chop-long-linesβ Truncate all lines longer than screen width. Alias for--wrap=never.--terminal-width <width>β Explicitly set the width of the terminal instead of determining it automatically. If prefixed with'+'or'-', the value will be treated as an offset to the actual terminal width. See also:--wrap.-n,--numberβ Only show line numbers, no other decorations. This is an alias for--style=numbers.--color <when>β Specify when to use colored output. The automatic mode only enables colors if an interactive terminal is detected. Possible values:auto(default),never,always.--italic-text <when>β Specify when to use ANSI sequences for italic text in the output. Possible values:always,never(default).--decorations <when>β Specify when to use the decorations that have been specified via--style. The automatic mode only enables decorations if an interactive terminal is detected. The always mode will show decorations even when piping output. Possible values:auto(default),never,always.-f,--force-colorizationβ Alias for--decorations=always --color=always. This is useful if the output ofbatis piped to another program, but you want to keep the colorization/decorations.--paging <when>β Specify when to use the pager. To disable the pager, use--paging=neveror its alias,-P. To disable the pager permanently, setBAT_PAGERto an empty string. To control which pager is used, see the--pageroption. Possible values:auto(default),never,always.--pager <command>β Determine which pager is used. This option will override thePAGERandBAT_PAGERenvironment variables. The default pager isless. If you provide--pager=builtin, use the built-inminuspager. To control when the pager is used, see the--pagingoption. Example:--pager "less -RF".
Note: By default, if the pager is set toless(and no command-line options are specified),batwill pass the following command line options to the pager:-R/--RAW-CONTROL-CHARS,-F/--quit-if-one-screenand-X/--no-init. The last option (-X) is only used forlessversions older than 530. The-Roption is needed to interpret ANSI colors correctly. The second option (-F) instructs less to exit immediately if the output size is smaller than the vertical size of the terminal. This is convenient for small files because you do not have to pressqto quit the pager. The third option (-X) is needed to fix a bug with the--quit-if-one-screenfeature in old versions ofless. Unfortunately, it also breaks mouse-wheel support inless. If you want to enable mouse-wheel scrolling on older versions ofless, you can pass just-R(as in the example above, this will disable the quit-if-one-screen feature). For less 530 or newer, it should work out of the box.
-m,--map-syntax <glob-pattern:syntax-name>...β Map a glob pattern to an existing syntax name. The glob pattern is matched on the full path and the filename. For example, to highlight*.buildfiles with the Python syntax, use-m '*.build:Python'. To highlight files named.myignorewith the Git Ignore syntax, use-m '.myignore:Git Ignore'. Note that the right-hand side is the name of the syntax, not a file extension.--ignored-suffix <ignored-suffix>β Ignore extension. For example:bat --ignored-suffix ".dev" my_file.json.devwill use JSON syntax, and ignore.dev.--theme <theme>β Set the theme for syntax highlighting. Use--list-themesto see all available themes. To set a default theme, add the--theme="..."option to the configuration file or export theBAT_THEMEenvironment variable (e.g.:export BAT_THEME="...").
Special values:
auto(default) β Picks a dark or light theme depending on the terminal's colors. Use--theme-lightand--theme-darkto customize the selected theme.auto:alwaysβ Variation ofautowhere the terminal's colors are detected even when the output is redirected.auto:system(macOS only) β Variation ofautowhere the color scheme is detected from the system-wide preference instead.darkβ Use the dark theme specified by--theme-dark.lightβ Use the light theme specified by--theme-light.
--theme-dark <theme>β Sets the theme name for syntax highlighting used when the terminal uses a dark background. To set a default theme, add the--theme-dark="..."option to the configuration file or export theBAT_THEME_DARKenvironment variable (e.g.export BAT_THEME_DARK="..."). This option only has an effect when--themeoption is set toautoordark.--theme-light <theme>β Sets the theme name for syntax highlighting used when the terminal uses a light background. To set a default theme, add the--theme-light="..."option to the configuration file or export theBAT_THEME_LIGHTenvironment variable (e.g.export BAT_THEME_LIGHT="..."). This option only has an effect when--themeoption is set toautoorlight.--list-themesβ Display a list of supported themes for syntax highlighting.-s,--squeeze-blankβ Squeeze consecutive empty lines into a single empty line.--squeeze-limit <squeeze-limit>β Set the maximum number of consecutive empty lines to be printed.--strip-ansi <when>β Specify when to strip ANSI escape sequences from the input. The automatic mode will remove escape sequences unless the syntax highlighting language is plain text. Possible values:auto,always,never(default).--style <style-components>β Configure which elements (line numbers, file headers, grid borders, Git modifications,..) to display in addition to the file contents. The argument is a comma-separated list of components to display (e.g.'numbers,changes,grid') or a pre-defined style ('full'). To set a default style, add the'--style=".."'option to the configuration file or export theBAT_STYLEenvironment variable (e.g.:export BAT_STYLE="..").
Okay so when a style shows up in more than one place, the "nearest" set of styles wins, periodt. Priority order: command-line arguments are the highest π
, then the BAT_STYLE environment variable, then the configuration file. And here's the cute part β if any set of styles is made entirely of components prefixed with + or -, it modifies the previous set instead of replacing it. It's giving additive energy β¨
By default, these components are enabled: changes, grid, header-filename, numbers, snip
Possible values: default, full, auto, plain, changes, header, header-filename, header-filesize, grid, rule, numbers, snip.
-r,--line-range <N:M>...β only prints the specified range of lines, for each file. Obsessed with how flexible this is, look:
--line-range 30:40
prints lines 30 to 40
--line-range :40
prints lines 1 to 40
--line-range 40:
prints lines 40 to the end of the file
--line-range 30:+10
prints lines 30 to 40
-L,--list-languagesβ displays a list of supported languages for syntax highlighting. Bestie, this is the vibe check for "does bat already know my language" π¦-u,--unbufferedβ this option exists for POSIX-compliance reasons (uis forunbuffered). The output is always unbuffered β this option is simply ignored. So yeah, it's decorative, but it's iconic decoration π--no-custom-assetsβ do not load custom assets.--config-dirβ show bat's configuration directory.--cache-dirβ show bat's cache directory.--diagnosticβ show diagnostic information for bug reports. Use this when something's broken and you need receipts π--acknowledgementsβ show acknowledgements. Give the people their flowers πΈ--set-terminal-titleβ sets the terminal title to filenames when you're using a pager. Main character energy for your terminal window π-h,--helpβ print this help message.-V,--versionβ show version information.
π«Ά POSITIONAL ARGUMENTS π«Ά
<FILE>...β files to print and concatenate. Use a dash (-) or no argument at all to read from standard input. Ngl, the-thing is such a slay π
π§ SUBCOMMANDS π§
cacheβ modify the syntax-definition and theme cache. Lowkey the most powerful little subcommand here, and we'll be seeing it again in a sec π
π FILES π
bat can also be customized with a configuration file. The location of that file depends on your operating system. To get the default path for your system, call:
bat --config-file
Alternatively, you can use the BAT_CONFIG_PATH environment variable to point bat at a non-default location of the configuration file. Very "choose your own adventure" of it π
To generate a default configuration file, call:
bat --generate-config-file
These are the related options:
--config-fileβ show path to the configuration file.--generate-config-fileβ generates a default configuration file.--no-configβ do not use the configuration file. (aka the "I'm ignoring my own settings" option, we've all been there π)
π¦ ADDING CUSTOM LANGUAGES π¦
bat supports Sublime Text .sublime-syntax language files, and can be customized to add additional languages to your local installation. To do this, add the .sublime-syntax language files to $(bat --config-dir)/syntaxes and run bat cache --build.
Example:
mkdir -p "$(bat --config-dir)/syntaxes"
cd "$(bat --config-dir)/syntaxes"
# Put new '.sublime-syntax' language definition files
# in this folder (or its subdirectories), for example:
git clone https://github.com/tellnobody1/sublime-purescript-syntax
# And then build the cache.
bat cache --build
Once the cache is built, the new language will be visible in bat --list-languages. Literally that easy.
If you ever want to remove the custom languages, you can clear the cache with bat cache --clear. No hard feelings, bestie π
π ADDING CUSTOM THEMES π
Similarly to custom languages, bat supports Sublime Text .tmTheme themes. These can be installed to $(bat --config-dir)/themes, and are added to the cache with bat cache --build.
π₯ INPUT PREPROCESSOR π₯
Much like less(1) does, bat supports input preprocessors via the LESSOPEN and LESSCLOSE environment variables. In addition, bat attempts to be as compatible with less's preprocessor implementation as possible.
To use the preprocessor, call:
bat --lessopen
Alternatively, the preprocessor may be enabled by default by adding the --lessopen option to the configuration file.
To temporarily disable the preprocessor if it is enabled by default, call:
bat --no-lessopen
These are the related options:
--lessopenβ enable the$LESSOPENpreprocessor.--no-lessopenβ disable the$LESSOPENpreprocessor if enabled (overrides--lessopen)
For more information, see theINPUT PREPROCESSORsection ofless(1). See also:bat(1)remembering that other manpages exist, which is honestly growth π
β MORE INFORMATION β
For more information and up-to-date documentation, visit the bat repo:
https://github.com/sharkdp/bat
And that's a wrap on thebat(1)man page, bestie! π This was the officialBAT(1)footer you just scrolled past β the source lives in the bat project (sharkdp/bat, linked right up there π), and the date stamp is whatever the page's own version line says. Go highlight something pretty. Mwah πβ¨π¦
π¦ where this page comes from
- alpine 3.24: bat-doc 0.26.1-r0 Β· Apache-2.0
- arch rolling: bat 0.26.1-3 Β· Apache-2.0 OR MIT
- epel 10: bat 0.26.1-4.el10_3 Β· Apache-2.0 AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND CC-BY-SA-3.0 AND LGPL-3.0-or-later AND GPL-2.0-only WITH GCC-exception-2.0 AND MIT AND Unicode-3.0 AND Unicode-DFS-2016 AND Unlicense AND WTFPL AND (0BSD OR MIT OR Apache-2.0) AND (Apache-2.0 OR BSL-1.0) AND (Apache-2.0 OR MIT) AND (Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT) AND (MIT OR Apache-2.0 OR Zlib) AND (Unlicense OR MIT)
- epel 9: bat 0.26.1-3.el9 Β· Apache-2.0 AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND CC-BY-SA-3.0 AND LGPL-3.0-or-later AND GPL-2.0-only WITH GCC-exception-2.0 AND MIT AND Unicode-3.0 AND Unicode-DFS-2016 AND Unlicense AND WTFPL AND (0BSD OR MIT OR Apache-2.0) AND (Apache-2.0 OR BSL-1.0) AND (Apache-2.0 OR MIT) AND (Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT) AND (MIT OR Apache-2.0 OR Zlib) AND (Unlicense OR MIT)
- fedora 43: bat 0.26.1-4.fc43 Β· Apache-2.0 AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND CC-BY-SA-3.0 AND LGPL-3.0-or-later AND GPL-2.0-only WITH GCC-exception-2.0 AND MIT AND Unicode-3.0 AND Unicode-DFS-2016 AND Unlicense AND WTFPL AND (0BSD OR MIT OR Apache-2.0) AND (Apache-2.0 OR BSL-1.0) AND (Apache-2.0 OR MIT) AND (Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT) AND (MIT OR Apache-2.0 OR Zlib) AND (Unlicense OR MIT)
- fedora 44: bat 0.26.1-1.fc44 Β· Apache-2.0 AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND CC-BY-SA-3.0 AND LGPL-3.0-or-later AND GPL-2.0-only WITH GCC-exception-2.0 AND MIT AND Unicode-3.0 AND Unicode-DFS-2016 AND Unlicense AND WTFPL AND (0BSD OR MIT OR Apache-2.0) AND (Apache-2.0 OR BSL-1.0) AND (Apache-2.0 OR MIT) AND (Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT) AND (MIT OR Apache-2.0 OR Zlib) AND (Unlicense OR MIT)
- fedora 44: bat 0.26.1-4.fc44 Β· Apache-2.0 AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND CC-BY-SA-3.0 AND LGPL-3.0-or-later AND GPL-2.0-only WITH GCC-exception-2.0 AND MIT AND Unicode-3.0 AND Unicode-DFS-2016 AND Unlicense AND WTFPL AND (0BSD OR MIT OR Apache-2.0) AND (Apache-2.0 OR BSL-1.0) AND (Apache-2.0 OR MIT) AND (Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT) AND (MIT OR Apache-2.0 OR Zlib) AND (Unlicense OR MIT)
- nixos 26.05: bat 0.26.1
- nixpkgs unstable: bat 0.26.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms