Bat is a cat command clone with advance syntax highlighting for a large number of programming and markup languages.
Despite the title of this article, we’ll not talk about cats and bats here, but about the
bat commands in Linux.
As you know, the
cat (short for concatenate) command is a utility in Linux. One of its most commonly known usages is to print the content of a file onto the standard output stream. But given more time spent in the command line, features like syntax highlighting come in very handy.
What’s bat Command
Bat is a drop-in replacement for the
cat command, with some additional cool features such as syntax highlighting, git integration and automatic paging.
bat pipes its own output to a pager (e.g
less) if the output is too large for one screen. If you would rather
bat work like
cat all the time (never page output), you can set
--paging=never as an option, either on the command line or in your configuration file.
bat command also allows you to search during output (if the output is longer than the screen height) using the
/ key binding, similarly to
It is possible to alias
cat directly to
bat in your shell configuration. To do this, add the following line to your
alias cat='bat --paging=never'
Then source the file:
bat just works out-of-the-box on Linux. No extra configuration needed. So, in order to use it, all you have to do is type:
bat command receives our strongest recommendation. It is such a useful utility that you’ll wonder how you managed without it.
- Syntax highlighting: Bat supports syntax highlighting for a large number of programming and markup languages.
- Git integration: Bat communicates with git to show modifications with respect to the index.
- Automatic paging: The command can pipe its own output to less if the output is too large for one screen.
- Display and highlight non-printable characters: You can use the
-Aoption to show and highlight non-printable characters.
- Including all of the
You see the difference. The
cat command shows the contents of the file in plain text format, whereas
bat shows output with syntax highlighting and order row number in a neat tabular column format.
Those interested in learning more about
bat can visit the project’s GitHub page.
Install bat in Linux
sudo apt install bat
Arch Linux users can install the
bat package from the Arch’s official repo:
sudo pacman -S bat
In order to install the
bat command on Fedora type:
sudo dnf install bat
You can install
bat with zypper on openSUSE:
sudo zypper install bat