LIVEReading: See Code Files in Color with bat — No Setup HassleTotal time: 5 minSteps: 6Worked first time: 95% LIVEReading: See Code Files in Color with bat — No Setup HassleTotal time: 5 minSteps: 6Worked first time: 95%
CBW
See Code Files in Color with bat — No Setup Hassle
Easygithub.com/sharkdp/bat2026-06-06

See Code Files in Color with bat — No Setup Hassle

bat is a drop-in replacement for the cat command that adds syntax highlighting, line numbers, and Git change markers. Install it once and reading any code or config file becomes much easier.

// Build stats

  • Total time5 min
  • Number of steps6
  • DifficultyEasy
  • Worked first time95%
// Before you start

What you need

  • A terminal (Mac, Linux, or Windows with WSL)
  • Admin/sudo access to install packages
  • An internet connection
01
Step 1 of 6

Install bat using your system's package manager

2 min

bat is available in every major package manager. Pick the one command that matches your operating system and run it. On Ubuntu/Debian the binary may be called 'batcat' instead of 'bat' — that is normal and covered in the next step.

Terminal · mac
$ # macOS (Homebrew)
$ brew install bat
$
$ # Ubuntu / Debian
$ sudo apt install bat
$
$ # Fedora
$ sudo dnf install bat
$
$ # Windows (winget)
$ winget install sharkdp.bat
What you should see
Package manager downloads and installs bat. The last line usually says something like 'Successfully installed bat' or shows a version number.
This might happen

On Ubuntu/Debian the command is 'batcat', not 'bat', after install.

Run 'batcat README.md' instead of 'bat README.md', or create an alias with: mkdir -p ~/.local/bin && ln -s $(which batcat) ~/.local/bin/bat

02
Step 2 of 6

Confirm bat is working

1 min

Before doing anything else, check that bat installed correctly and that your terminal can find it. This command prints the version number.

Terminal · mac
$ bat --version
What you should see
bat 0.24.0 (or any version number — exact number does not matter)
This might happen

'bat: command not found' error.

On Ubuntu/Debian try 'batcat --version'. On other systems, close and reopen your terminal so the new install is picked up, then try again.

03
Step 3 of 6

View a file with syntax highlighting

1 min

This is the main thing bat does. Point it at any file and it prints the contents with color-coded syntax, line numbers, and a decorative border. Try it on any file you have handy — a config file, a script, anything.

Terminal · mac
$ bat /etc/hosts
What you should see
Your terminal shows the file contents with colored text, line numbers on the left, and a header bar showing the filename. If the file is long, it opens in a scrollable pager — press Q to quit.
This might happen

Output scrolls and you cannot get back to the prompt.

Press Q to exit the pager. To disable paging permanently, add --paging=never to your command: bat --paging=never /etc/hosts

04
Step 4 of 6

View multiple files at once

1 min

bat can display several files back-to-back in one command. Each file gets its own header so you always know which file you are reading.

Terminal · mac
$ bat /etc/hosts /etc/hostname
What you should see
Both files are printed one after the other, each with its own colored header bar and line numbers.
05
Step 5 of 6

Make bat your default cat with an alias

3 min

If you want bat to run every time you type 'cat', add an alias to your shell config file. This change only takes effect in new terminal windows unless you also reload the file.

Terminal · mac
$ # For bash users — adds the alias and reloads config
$ echo "alias cat='bat --paging=never'" >> ~/.bashrc && source ~/.bashrc
$
$ # For zsh users (default on modern Macs)
$ echo "alias cat='bat --paging=never'" >> ~/.zshrc && source ~/.zshrc
What you should see
No output means it worked. Type 'cat /etc/hosts' and you should now see the colorized bat output instead of plain text.
This might happen

You added the alias but 'cat' still behaves the old way.

Close and reopen your terminal, or run 'source ~/.bashrc' (or ~/.zshrc) again. The alias only applies to new shell sessions unless you reload the config.

06
Step 6 of 6

Colorize man pages for easier reading

2 min

bat can replace the default man page viewer so that manual pages display with colors instead of plain text. You set one environment variable in your shell config to make this permanent.

Terminal · mac
$ # For bash
$ echo "export MANPAGER='bat -plman'" >> ~/.bashrc && source ~/.bashrc
$
$ # For zsh
$ echo "export MANPAGER='bat -plman'" >> ~/.zshrc && source ~/.zshrc
$
$ # Test it
$ man ls
What you should see
The man page for 'ls' opens with colored headings and highlighted text instead of the usual plain monochrome output. Press Q to exit.
This might happen

Man page looks garbled or shows raw formatting codes.

On older Debian/Ubuntu the binary is 'batcat'. Change the export line to: export MANPAGER='batcat -plman'

// Status

cooked. baked. worked.

You have bat installed and working as a colorized file viewer. Typing 'bat filename' shows any file with syntax highlighting and line numbers. Optionally, 'cat' and 'man' are aliased to use bat automatically in every new terminal session.

// the honest bit

The honest part

bat is a display tool only — it does not edit files. Git change markers only appear if you are inside a Git repository. Syntax highlighting depends on bat recognizing the file type; obscure or custom file extensions may show no highlighting. The alias approach means scripts or other programs that call 'cat' directly are unaffected — only your interactive terminal sessions change.