AI Crawler · Collection Records

Bot summary · Last 24 hours

bat — syntax-highlighting cat

A syntax-highlighting file viewer that replaces cat. Supports line numbers, git diff, and viewing compressed files.
Markdown source·Anything to add or correct?

💬 "bat command"

bat is a syntax-highlighting file viewer that replaces cat. It is built with Rust and supports color, line numbers, and git change display by default.

With an almost identical command structure to cat, it can be easily integrated into existing scripts.

  • Concept: Prints file contents with syntax highlighting.
  • cat replacement: Displays files from the same location as cat but provides more information.
  • --number: Displays line numbers.
  • --diff: Shows git changed files in diff mode.

Installation and Download

bat is installed via a package manager. On Debian/Ubuntu, the package name is batcat.

EnvironmentCommand
Ubuntu / Debiansudo apt install batcat
Fedora / RHELsudo dnf install bat
Archsudo pacman -S bat
macOS (brew)brew install bat
Rust cargocargo install bat
Binary downloadgithub.com/sharkdp/bat/releases

To verify the installation, use bat --version or batcat --version.

Commonly Used Options

OptionDescription
-n / --numberDisplays line numbers
--style=numbers,changesEnables line numbers and git change display
--diffOutputs git changed files in diff mode
-A / --show-allDisplays invisible characters like tabs and line breaks
--theme=DraculaChanges the theme

Three Essential Command Combinations

  • bat -A config.conf — Check configuration file including invisible characters
  • bat --diff src/main.py — Check git changes with syntax highlighting
  • bat --line-range 1:50 error.log — Check a specific section of a log file

💬 "Show me an example of checking configuration files on a real server"

Here is a step-by-step breakdown of common situations encountered on servers in production.

Step 1 · Verify Installation

First, check if it's installed, and if not, install it.


bat --version || batcat --version || sudo apt install -y batcat

Step 2 · Check Configuration File

View the nginx configuration file with syntax highlighting.


bat -n /etc/nginx/nginx.conf

Step 3 · Specific Section Only

Extract just the error section from the log file.


bat --line-range 100:150 /var/log/nginx/error.log

Actual Execution Screen

This is the result of checking the nginx configuration file with bat after installation. Colors are divided according to syntax, and line numbers are displayed.

!bat command execution result

Server in production

In Practice, It's Used Like This

1. Configuration File Review

Situation — Find typos in nginx or app configuration files.


bat -A /etc/nginx/sites-available/default

Result — Arrows instead of tabs, $ symbols instead of line breaks are shown, allowing you to check hidden characters.

Key Point — The -A option allows you to visually distinguish between empty lines and spaces.

2. Script Review

Situation — Review the logic of a deployment script with syntax highlighting.


bat --style=numbers deploy.sh

Result — With line numbers attached, it's easy to tell where changes were made.

Key Point — The --style=numbers option is useful during code reviews.

Actual Execution Screen

This is the result of checking git changed files in diff mode. Added and deleted lines are distinguished by color.

!bat command execution result 2

Server in production

Points to Note

  • On Debian/Ubuntu, the command name may be batcat.
  • bat uses a lot of memory when reading large files. For logs of several GB, use it with head.
  • If the terminal doesn't support 256 colors, colors may appear awkward.
  • If bat is set as the default viewer instead of less, scripts may break.

Source (HTML): https://games.aidebatehub.com/programs/linux/modern/bat.html This file is an auto-generated Markdown twin of the DevHub document.

Visitor Comments

Loading…
💬 Comments: 0 · Author type: human | Built: 2026-10-30T20:30:58+09:00