LINUXMIND.DEVTHE GNU/LINUX WORLD

LinuxMind trick: bat, the cat that finally reads well in colour

Ilustracion editorial plana de una pagina con bandas de color y numeros de linea, el visor bat

You have stared at cat output a thousand times: a wall of one-colour text where you cannot tell a comment from a string, and nothing has a line number. Today’s LinuxMind trick is bat, a cat clone with syntax highlighting, line numbers and a git-aware margin — the reader your terminal has been missing all along.

The problem

cat is perfect at exactly one job: dumping bytes to the screen. The trouble is that human eyes need help. Open a config file and comments, keys and values all look identical; scroll through a script and you have no line numbers to point at; diff a file and you get no sense of what changed. It works, but it never helps. And when you are chasing a bug at midnight, “it works” is not enough.

The LinuxMind trick

bat is a drop-in replacement for cat that adds everything the terminal left out: automatic syntax highlighting for hundreds of languages, line numbers in the margin, a header showing the filename and size, and a git gutter that marks added, changed and removed lines. It pages long files, respects your theme, and stays quiet when you pipe it into another program — so it never breaks a script. It is cat for humans, without giving up being cat for machines.

The command

# Install it (pick your distro)
sudo apt install bat         # Debian / Ubuntu (command is batcat)
sudo dnf install bat         # Fedora

# Read a file in colour, with line numbers
bat ~/.bashrc

# Replace cat with bat for good (add to ~/.bashrc)
alias cat='bat --paging=never'

Why it hooks you

Because it is zero-effort and it is safe. You keep the muscle memory of cat, but every file you open is instantly readable, and on Ubuntu you can even alias batcat back to bat so the name stays clean. The git gutter is the quiet killer: once you can see at a glance which lines you touched, plain cat feels like reading without your glasses.

Extra tricks

It plays well with the tools you already run:

Command What it does
bat file Syntax highlighting plus line numbers for any source file
bat --diff file Shows a git-style gutter marking added and removed lines
man via bat Read a man page in colour by piping it through bat
bat -n Force line numbers on when reading from a pipe
bat --theme Pick a built-in theme to match your terminal colours

Install it, alias cat to it with paging off, and give it a week. The first time you open a log or a config and can actually see the structure, you will not want to go back — bat is the small upgrade that makes the whole terminal easier to read.

Sources




Leave a Reply

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