In Linux to see any file most of linux users using cat command which is one of most used command on Linux operating system from that time of its origin. It has no formatting pattern for any type of files.So in case we have some command which could work exactly like cat with formatting highlighting.

Bat features

Bat has various features that we should discussed know about before going to start this post
1. Bat has syntax highlighting features
2. Support for various languages
3. various supportive theme
4. Support themes
5. By-default open in less style, so in case file is long, it will open in windows
6. User-friendly command line user interface

Install of Bat

Let’s how and from where we can install this package. We can install bat on many Operating systems through their package manager or get it download from bat github link.

Like in case of Ubuntu Machine we can install it through apt-get install command.

root@srv21:~# lsb_release -d                                                          
Description:    Ubuntu 20.04 LTS
root@srv21:~# apt-get install bat
Reading package lists... Done                                                         
Building dependency tree                                                              
Reading state information... Done                                                     
The following additional packages will be installed:                                  
  libgit2-28 libhttp-parser2.9 libmbedcrypto3 libmbedtls12 libmbedx509-0 libssh2-1    
The following NEW packages will be installed:                                         
  bat libgit2-28 libhttp-parser2.9 libmbedcrypto3 libmbedtls12 libmbedx509-0 libssh2-1
0 upgraded, 7 newly installed, 0 to remove and 7 not upgraded.                        
Need to get 2,349 kB of archives.                                                     
After this operation, 6,556 kB of additional disk space will be used.                 
Do you want to continue? [Y/n] y                                                      

In case we are not able to get package through package manager, we can download it though bat github page.

We can download our suitable packages from link and install through dpkg -i

dpkg -i bat_0.15.4_amd64.deb

We can even install this package on RedHat/CentOS Machine , there are some third-party repositories present on internet, you can download packages from there.

rpm -ivh http://repo.openfusion.net/centos7-x86_64/bat-0.7.0-1.of.el7.x86_64.rpm            
Retrieving http://repo.openfusion.net/centos7-x86_64/bat-0.7.0-1.of.el7.x86_64.rpm          
warning: /var/tmp/rpm-tmp.DuqtWp: Header V4 DSA/SHA1 Signature, key ID 2a6b914a: NOKEY      
Preparing...                          ################################# [100%]              
Updating / installing...                                                                    
   1:bat-0.7.0-1.of.el7               ################################# [100%]              

Use of bat

We can open any normal file through bat command, but it’s good check some script or program like below. I tried to open some small bash and python script

In above examples, might you understand features and capabilities of bat command. I am sharing image so you could see proper color in bat command output.Same would happened with python scripts.

Various languages supported through bat, we could try them to open files

bat --list-languages 

There are various themes with bat command, which could identify and use like below.

bat --theme TwoDark mysql_status 

or 

bat --theme "Monokai Extended Light" mysql_status

We try to open same file with two different themes like below.

Now we know another way to open files for see Linux files with some good viewing capabilities.