You can support us by downloading this article as PDF from the Link below. Download the guide as PDF

Bat is a cat(1) clone with syntax highlighting and Git integration. If you need an amazing experience while working with the cat command, then this tool is definitely for you. Bat supports syntax highlighting for a large number of programming and markup languages.

Features of bat – cat alternative tool

  • Automatic paging:  bat can pipe its own output to less if the output is too large for one screen.
  • Git integration:  bat communicates with git to show modifications with respect to the index
  • Syntax highlighting: Native support for syntax highlighting for a large number of programming and markup languages:
  • File concatenation: Whenever bat detects a non-interactive terminal, it will fall back to printing the plain file contents.

Install bat on Ubuntu / Debian

There is a bat Debian package available on Github releases page. Check the latest release version before downloading with this method.

rm -f bat*
curl -s |grep browser_download_url |  cut -d '"' -f 4 | grep 'amd64.deb' | grep -v musl | wget -i -
sudo dpkg -i bat_*_amd64.deb

Sample installation output:

Selecting previously unselected package bat.
(Reading database ... 63420 files and directories currently installed.)
Preparing to unpack bat_0.18.0_amd64.deb ...
Unpacking bat (0.18.0) ...
Setting up bat (0.18.0) ...
Processing triggers for man-db (2.9.1-1) ...

You can also install directly using package manager. This won’t guarantee installation of the latest release:

sudo apt install bat

Install bat command on Arch Linux

For Arch Linux users, bat package is available on upstream repositories and you can install it using pacman package manager.

sudo pacman -S bat

Install bat command on Void Linux

On a Void Linux system, install bat using the following commands:

xbps-install -S bat

Install bat on Alpine Linux

sudo apk add bat

Install bat command on macOS

You can install bat with Homebrew:

brew install bat

Install bat command on Fedora

For Fedora perform the installation using dnf package manager:

sudo dnf install bat

Install bat command on Gentoo

Use the command:

sudo emerge sys-apps/bat

Install bat command on FreeBSD:

sudo pkg install bat

How to use bat command on Linux

Here are few examples on how you can use bat

To view contents of a file, use:

$ bat <file>
bat cat file

Display multiple files at once

$ bat code/*.yml

You can also read  input from stdin, explicitly specify the language

$ yaml2json playbook.yml | json_pp | bat -l json
curl -s | bat -l rs

To see all supported languages, use:

$ bat --list-languages

All other standard cat commands should work, e.g:

Creating a new file

$ bat >

Combine three files output to one

$ bat >

Show file

$ bat -n
$ bat f - g # output 'f', then stdin, then 'g'.

Change Highlighting theme

To get a list of all available themes for syntax highlighting, run:

$ bat --list-themes

Set a theme by calling bat command with the --theme option.

$ bat --theme=DarkNeon

The same can be achieved by using BAT_THEME environment variable.

export BAT_THEME="DarkNeon"

This can be added to your ~/.bashrc | ~/.zshrc file

Check complete help page using

$ bat --help
bat 0.18.0
A cat(1) clone with syntax highlighting and Git integration.

    bat [OPTIONS] [FILE]...
    bat <SUBCOMMAND>

    -l, --language <language>
            Explicitly set the language for syntax highlighting. The language can be
            specified as a name (like 'C++' or 'LaTeX') or possible file extension (like
            'cpp', 'hpp' or 'md'). Use '--list-languages' to show all supported language
            names and file extensions.
            Display a list of supported languages for syntax highlighting.

        --theme <theme>
            Set the theme for syntax highlighting. Use '--list-themes' to see all
            available themes. To set a default theme, export the BAT_THEME environment
            variable (e.g.: export BAT_THEME="TwoDark").
            Display a list of supported themes for syntax highlighting.

        --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') [default: auto]
            [possible values: auto, full, plain, changes,
            header, grid, numbers]
    -p, --plain
            Only show plain style, no decorations. This is an alias for '--style=plain'

    -n, --number
            Only show line numbers, no other decorations. This is an alias for
        --line-range <N:M>
            Only print the specified range of lines for each file. For example:
              '--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
        --color <when>
            Specify when to use colored output. The automatic mode only enables colors if
            an interactive terminal is detected. [default: auto]  [possible values:
            auto, never, always]
        --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. [default: auto]  [possible values: auto, never,
        --paging <when>
            Specify when to use the pager. To control which pager is used, set the PAGER
            or BAT_PAGER environment variables (the latter takes precedence). The default
            pager is 'less'. To disable the pager permanently, set BAT_PAGER to an empty
            string. [default: auto]  [possible values: auto, never,
        --wrap <mode>
            Specify the text-wrapping mode. [default: character]  [possible values:
            character, never]
            This option exists for POSIX-compliance reasons ('u' is for 'unbuffered'). The
            output is always unbuffered - this option is simply ignored.
    -h, --help
            Print this help message.

    -V, --version
            Show version information.

            File(s) to print / concatenate. Use a dash ('-') or no argument at all to read
            from standard input.

            Modify the syntax-definition and theme cache

For further customizations, check the official Bat Github page.

As an appreciation for the content we put out,
we would be thrilled if you support us!

As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.


Please enter your comment!
Please enter your name here