In linux, you must be familiar with cat commands. It is used often to print and concatenate files. Bat command is a clone of cat command which comes with many attractive and useful features. Some of the features are syntax highlighting, automatic paging, git integration and so on, that enhances the experience of programmers too.
- Git integration: bat communicates with git to show modifications.
- Syntax highlighting: bat supports syntax highlighting for a large number of programming and markup languages.
- Automatic paging: bat is able to pipe its own output to less, if in case the output is too large for one screen.
- Command line interface is very user-friendly.
In this article, we will install and show the uses and features of bat command. Here, we are going to install it on Ubuntu 20.04 LTS server.
Bat package can be installed from the package manager with the following command.
$ sudo apt install bat
But it can install any version of bat package so to make sure the bat package is the latest one, we are downloading it from the Github release page. You can simply search the page or run the following command as shown below.
$ wget https://github.com/sharkdp/bat/releases/download/v0.18.3/bat-musl_0.18.3_amd64.deb $ sudo dpkg -i bat-musl_0.18.3_amd64.deb
As the installation of the bat package is completed, we can simply use it with the bat command. Some of the examples are shown below.
$ bat filename
$ bat test.txt
$ bat <file1> <file2>
$ bat /etc/hosts test.txt
$ bat --list-languages
$ bat file1 file2 > singlefile
$ bat test.txt app.txt > document.txt
$ bat > filename
$ bat > hello.txt
$ bat --line-range range_from:range_to filename
$ bat --line-range 2:4 /etc/hosts
$ bat -n filename
$ bat -n zigzag.py
$ bat filename
$ bat zigzag.py
$ bat --list-themes
$ bat --theme=ansi filename
$ bat --theme=ansi zigzag.py
To make these changes of themes permanent, write “export BAT_THEME=”ansi” on ~/.bashrc for user specific or /etc/bash.bashrc for system wide.
Bat is a clone of cat command which comes with many features as shown in the above examples. You can try using other themes too as per your preference. Explore the bat command with “man bat” for more details.Thank you!
I am a professional WordPress & Graphic designer. I have more than 6 years of experience in this field.