Bat is a cat command clone with advanced 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 are convenient.
What’s bat Command
Bat is a drop-in replacement for the
cat command, with additional cool features such as syntax highlighting, git integration, and automatic paging.
bat pipes its output to a pager (e.g.,
less) if the output is too large for one screen.
However, if you would instead
bat work like the
cat command 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 works out-of-the-box on Linux. No extra configuration is needed. So, to use it, all you have to do is type:
bat command receives our strongest recommendation. It is a helpful utility that you’ll wonder how you managed without it.
- Syntax highlighting: Bat supports syntax highlighting for many 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
lessif it 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 file’s contents in plain text format, whereas the
bat command shows the output with syntax highlighting and ordering row numbers in a neat tabular column format.
Those interested in learning more about the
bat command in Linux can visit the project’s GitHub page.
Installing the bat Command in Linux
We should utilize the system package manager. Let’s look at several well-known Linux distribution examples for installing the bat command.
sudo apt install bat
sudo pacman -S bat
To install the
bat command on Fedora, type:
sudo dnf install bat
You can install
zypper on openSUSE:
sudo zypper install bat
This short article covered how to install and use the
bat command on Linux. In my opinion, the
bat command is an excellent modern tool for Linux users. So, give it a shot and let us know what you think.