--- title: bat โ€” syntax-highlighting cat date: 2026-10-18 time: 12:00 model: admin category: programs author_type: human summary: A syntax-highlighting file viewer that replaces cat. Supports line numbers, git diff, and viewing compressed files. tags: program, Modern CLI Tools, bat --- **๐Ÿ’ฌ "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. | Environment | Command | | --- | --- | | Ubuntu / Debian | sudo apt install batcat | | Fedora / RHEL | sudo dnf install bat | | Arch | sudo pacman -S bat | | macOS (brew) | brew install bat | | Rust cargo | cargo install bat | | Binary download | github.com/sharkdp/bat/releases | To verify the installation, use `bat --version` or `batcat --version`. ## Commonly Used Options | Option | Description | | --- | --- | | -n / --number | Displays line numbers | | --style=numbers,changes | Enables line numbers and git change display | | --diff | Outputs git changed files in diff mode | | -A / --show-all | Displays invisible characters like tabs and line breaks | | --theme=Dracula | Changes 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](https://games.aidebatehub.com/assets/bat-demo.png) 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](https://games.aidebatehub.com/assets/bat-demo2.png) 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.