What Is the Bat Command?
If you spend any time in the terminal, you use cat. It dumps file contents to your screen. It works. But it’s also boring. Your files have colors, syntax, and structure, and cat shows you none of it.
That’s where bat comes in. The bat command is a modern replacement for cat that adds syntax highlighting, line numbers, Git integration, and a few other quality-of-life features. It’s written in Rust, it’s fast, and it works the same way cat does for basic use. You drop it in and everything looks better.
Bat has over 50,000 stars on GitHub. It’s maintained by the same people who make fd and ripgrep. If you already use eza for listing files, bat is the next logical step in upgrading your terminal.
How to Install the Bat Command on Linux
Installing the bat command on Linux is straightforward on most distributions.
On Debian or Ubuntu:
sudo apt install bat
The package might be called bat or batcat depending on your distro. On Debian-based systems it’s usually batcat because of a naming conflict with another package. If that happens, just add an alias:
alias bat='batcat'
On Fedora:
sudo dnf install bat
On Arch:
sudo pacman -S bat
If package managers aren’t your thing, grab the latest binary from the bat GitHub releases page. It’s a single binary you can drop anywhere on your PATH.
I use bat on every machine I work on. It’s one of those tools you install once and forget about, until you’re on a server that doesn’t have it and you realize how much you miss it.
1. Syntax Highlighting Out of the Box
This is the main reason people switch to the bat command. Run bat on a Python, JavaScript, JSON, or YAML file and it automatically highlights the syntax. You don’t need to configure anything. Bat detects the language from the file extension and applies the right colors.
Compare this:
cat app.py
To this:
bat app.py
The difference is night and day. Variables, strings, keywords, and comments each get their own color. It makes reading configuration files ten times easier. I’ve spotted missing commas and wrong indentation just because bat highlighted them.
If you use a dark terminal theme, bat picks a matching color scheme by default. You can switch themes with --theme if you want something different. Bat ships with dozens of themes, including Monokai from Sublime Text and One Half Dark from Visual Studio.
2. Line Numbers by Default
Bat shows line numbers on every file. No more piping output through cat -n or nl. Every file you open with the bat command has numbered lines on the left side.
This saves time when you’re debugging. The error is on line 42 and it’s right there in front of you. Someone asks what’s at line 87 of nginx.conf and you have the answer in less than a second.
You can disable line numbers with -n if you need to copy output without them. I leave them on for almost everything.
3. Git Integration Shows Changes as You Read
This is my favorite feature. When you use the bat command on a file tracked by Git, it shows a column on the left that marks modified lines. A + means the line was added. A ~ means it was changed. Nothing means it hasn’t been touched.
Open a file in a Git repo. You see syntax-highlighted code with line numbers on the left and a Git gutter column next to them. It looks like a diff inside your file viewer. You can instantly see what changed since your last commit.
This alone has saved me from pushing debug code more times than I want to admit.
4. Show Hidden Characters with -A
Ever opened a file and wondered why it behaves weird? The answer is often invisible characters. Tabs that should be spaces, trailing whitespace that breaks your linter, newline formats that don’t match.
Bat can show you all of this. Use the -A or --show-all flag:
bat -A config.yaml
Now every tab shows as →, every space as ·, and every newline as ␊. This is incredibly useful when YAML files break because someone used a tab instead of spaces. Or when a shell script behaves differently on two machines and you need to find the hidden difference.
I don’t use -A every day. But the days I need it, nothing else helps as fast.
5. Built-in Paging for Long Files
Bat automatically pipes long output through a pager, usually less. If your file fits on screen, bat just prints it. If it’s longer, it opens in a pager so you can scroll.
This means you never type cat log.txt | less again. The bat command handles the decision for you. Disable paging with --paging=never or force it with --paging=always.
For log files this is a convenience that saves a lot of keystrokes over a week of work.
6. Works as a Drop-In Cat Replacement
Bat does everything cat does. You can concatenate files:
bat file1.txt file2.txt > combined.txt
You can use it in pipes:
bat data.json | jq '.users'
You can redirect output. Your existing scripts and aliases keep working. The only difference is that when you read the output interactively, it looks better. The bat command is a drop-in replacement that upgrades the experience without breaking anything.
7. Custom Themes and Configuration
Bat reads a config file at ~/.config/bat/config. You can set your theme, toggle paging, and change the style permanently instead of passing flags every time.
Here is a basic config I use:
--theme="Dracula"
--style="plain"
--paging=never
If your terminal uses a light background, try --theme="GitHub" for a clean look. For dark terminals, --theme="TwoDark" or --theme="OneHalfDark" work well.
You can also set BAT_THEME as an environment variable in your shell config:
export BAT_THEME="Dracula"
This keeps things consistent across every terminal session.
A Practical Bat Command Workflow
Here is how I use the bat command in a real scenario. You are troubleshooting a failed CI build. The logs point to a Docker Compose file. You open it:
bat docker-compose.yml
You see the file with full syntax highlighting. Line 34 has a Git marker showing it was changed recently. You spot the problem, a tab where spaces should be in the YAML indentation. You run:
bat -A docker-compose.yml
The tab shows as → on line 34. One fix later, the build passes.
That is the kind of daily use that makes bat worth installing. It does not reinvent file reading. It just makes it work better.
Related Modern Linux Tools
If you like bat, check out other modern CLI replacements. Eza replaces ls with colors and icons. Ripgrep replaces grep with lightning-fast search. Fzf adds fuzzy finding to almost any command. Together they form a modern terminal toolkit that makes daily work faster.
For an even wider overview of modern alternatives to classic Linux commands, check out this guide to modern Linux command alternatives and the OpenSource.com article on 5 modern CLI tools.
Wrap Up
The bat command on Linux is a small upgrade that makes a big difference in your daily workflow. Syntax highlighting, line numbers, Git integration, and built-in paging work together to make reading files faster and less error-prone.
Install it. Set up your theme. Alias it if you are on Debian. You will wonder why you did not switch sooner.