A Modern Alternative to the Classic Linux cat Command

If you don’t like the dull and boring output of the cat command, consider installing bat on your Linux machine.

The cat utility predates Linux, but you might wonder if there’s something better than this standard utility. If you want to examine files in Linux, there’s a newer utility named bat that you might be interested in.

What Is bat?

bat homepage

bat is a clone of cat with some modern features. The tagline on its GitHub page is “a cat clone with wings.”

One major feature is the addition of line numbers to any output. It also automatically recognizes several programming languages and highlights syntax. It also integrates seamlessly with Git.

Installing bat on Linux

Installing bat on a Linux desktop is easy enough. It’s available in many Linux distribution’s official repositories.

To install bat on Ubuntu or Debian, just use APT:

sudo apt install bat

Running it on Debian and Ubuntu is a little different, as will be explained later.

To install bat on Arch Linux:

sudo pacman -S bat

And on Fedora/Red Hat/CentOS:

sudo dnf install bat

Using bat to View Output on Linux

Running bat is similar to using cat. You can use it with files or with standard input. You can call it at the command line with “bat.”

If you’re on Ubuntu or Debian, call it by typing “batcat” instead. You can change it back to “bat” by creating a shell alias with:

alias batcat="bat"

Stick this in your shell configuration file (usually .bashrc or .zshrc) to make it permanent.

Linux bat utility showing syntax highlighting for a C

The first thing you’ll notice is that bat draws a border around the output with line numbers. This seems to just make it prettier. The standard cat program does have the -n option to display line numbers.

bat -n option showing line numbers

If you don’t like the decorations, you can use the -n to only display line numbers.

bat will detect many popular programming languages and highlight the syntax. You can use the -l option to force the detection of a particular language, such as C.

bat -l c file.c

A Modern Alternative to the cat Command

bat is a modern alternative to the classic Linux cat command. It offers some unique features, such as pretty-printing line numbers, paging, and syntax highlighting.

bat is not the only modern take on classic Unix utilities out there. There are many replacements for time-tested utilities like grep or man that you might want to check out.

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *