bat
Overview
bat is a modern cat clone with syntax highlighting, Git integration, line numbering, and automatic paging.
Syntax
bat [options] [file...]Common Options
| Option | Description |
|---|---|
-l, --language LANG |
Force syntax highlighting for a specific language |
-p, --plain |
Plain mode (disable line numbers, headers, and decorations) |
-A, --show-all |
Show non-printable characters (tabs, spaces, newlines) |
--diff |
Show only lines that have changed relative to the Git index |
Key Use Cases
- Reading source code files with auto-detected syntax coloring.
- Viewing Git repository file changes directly in the shell.
- Quick code inspection with line numbers.
Examples with Explanations
Example 1: View File with Syntax Highlighting
bat script.pyDisplays script.py with automatic syntax highlighting and line numbers.
Example 2: View Git Diff Context
bat --diff index.qmdDisplays index.qmd showing added/modified line markers from Git.