# bat

> A cat clone with syntax highlighting, Git integration, and automatic paging for viewing files in the terminal.

Stars: 61.0k · Language: Rust · License: MIT · Categories: File Management

- Repository: https://github.com/sharkdp/bat
- Page: https://www.trmn.sh/tools/bat

## Install

- Homebrew: `brew install bat`
- apt: `sudo apt install bat`
- pacman: `pacman -S bat`

## Overview

bat is a command-line file viewer that extends the functionality of the traditional cat command. It provides syntax highlighting for a large number of programming and markup languages, making code and configuration files more readable when displayed in the terminal. The tool automatically detects file types and applies appropriate syntax coloring.

The tool integrates with Git repositories to display file modifications in the left sidebar, showing additions, deletions, and changes relative to the Git index. bat includes automatic paging functionality, piping output through less or similar pagers when content exceeds screen size, but falls back to plain cat-like behavior when piped to other processes or files.

bat supports displaying non-printable characters with the -A/--show-all option and can read from stdin with automatic or explicit syntax detection. It integrates well with other command-line tools like fzf (as a file previewer), ripgrep (via batgrep), and can serve as a colorizing pager for man pages. The tool maintains backward compatibility with cat, supporting file concatenation and standard input/output redirection.

Developers, system administrators, and command-line users who frequently view code files, logs, or configuration files will find bat useful as a direct replacement for cat with enhanced readability features.

### Installation

```bash
# via Homebrew
brew install bat
```

```bash
# via apt
sudo apt install bat
```

```bash
# via pacman
pacman -S bat
```

![Syntax highlighting example](https://media.trmn.sh/cached/82f72617f0ef395d40aca87859abe6816c5a427c66a21512d0ef2a9c7b38e1b6.png)

![Git integration example](https://media.trmn.sh/cached/260a267fd84333e9c3362830e84afa87ac6c0829a332312b011f1d05449e4de2.png)

![Non-printable character example](https://media.trmn.sh/cached/76be17a604b0ca9e50a1ad7c214a39e065b2725d1bb28b17502e1d7fa435dc11.png)

## Alternatives

- [yazi](https://www.trmn.sh/tools/yazi.md): Asynchronous terminal file manager written in Rust with image preview, plugin system, and cross-directory operations (Rust, 43.2k stars)
- [eza](https://www.trmn.sh/tools/eza.md): Modern replacement for ls with colors, Git integration, tree view, and extended file metadata display. (Rust, 23.7k stars)
- [lsd](https://www.trmn.sh/tools/lsd.md): Enhanced ls replacement with colors, icons, tree view, and additional formatting options written in Rust (Rust, 16.3k stars)
- [broot](https://www.trmn.sh/tools/broot.md): Interactive file manager and directory navigator with fuzzy search, git integration, and file operations (Rust, 13.1k stars)
- [dust](https://www.trmn.sh/tools/dust.md): A disk usage analyzer that shows directory sizes with visual bars and intelligent tree traversal (Rust, 12.6k stars)

## Guides

- [Search your shell history with fzf](https://www.trmn.sh/guides/fzf-history-search): Replace the default Ctrl-R with a fuzzy history search in bash, zsh or fish using fzf's shell integration.
- [Swap ls, cat, find and grep for eza, bat, fd and ripgrep](https://www.trmn.sh/guides/modern-unix-replacements): Install eza, bat, fd and ripgrep, learn the side-by-side commands and flag differences, and alias them without breaking your scripts.

---

Canonical: https://www.trmn.sh/tools/bat
