sharkdp /bat

A cat(1) clone with wings.

★ 61,271⑂ 2,334👁 266⑃ 2,316● 1,650▤ 43◈ 92
RustApache-2.0Created 2018-04-21
TA的项目
61,271
stars
+19
2,334
forks
266
watchers
2,316
prs
1,650
issues
43
releases
92
discussions

README

A cat(1) clone with syntax highlighting and Git integration.



  Key Features •
  How To Use •
  Installation •
  Customization •
  Project goals, alternatives
  [English]
  [中文]
  [日本語]
  [한국어]
  [Русский]


 Syntax highlighting

bat supports syntax highlighting for a large number of programming and markup
languages:

!Syntax highlighting example

 Git integration

bat communicates with git to show modifications with respect to the index
(see left sidebar):

!Git integration example

 Show non-printable characters

You can use the -A/--show-all option to show and highlight non-printable
characters:

!Non-printable character example

 Automatic paging

By default, bat pipes its own output to a pager (e.g. less) if the output is too large for one screen.
If you would rather bat work like cat all the time (never page output), you can set --paging=never as an option, either on the command line or in your configuration file.
If you intend to alias cat to bat in your shell configuration, you can use alias cat='bat --paging=never' to preserve the default behavior.

 File concatenation

Even with a pager set, you can still use bat to concatenate files :wink:.
Whenever bat detects a non-interactive terminal (i.e. when you pipe into another process or into a file), bat will act as a drop-in replacement for cat and fall back to printing the plain file contents, regardless of the --pager option's value.

 How to use

Display a single file on the terminal

bash
bat README.md


Display multiple files at once

bash
bat src/.rs


Read from stdin, determine the syntax automatically (note, highlighting will
only work if the syntax can be determined from the first line of the file,
usually through a shebang such as !/bin/sh)

bash
curl -s https://sh.rustup.rs | bat


Read from stdin, specify the language explicitly

bash
yaml2json .travis.yml | json_pp | bat -l json


Show and highlight non-printable characters:
bash
bat -A /etc/hosts


Use it as a cat replacement:

bash
bat  note.md   quickly create a new file

bat header.md content.md footer.md  document.md

bat -n main.rs   show line numbers (only)

bat f - g   output 'f', then stdin, then 'g'.


 Integration with other tools

 fzf

You can use bat as a previewer for fzf. To do this,
use bat's --color=always option to force colorized output. You can also use --line-range
option to restrict the load times for long files:

bash
fzf --preview "bat --color=always --style=numbers --line-range=:500 {}"


For more information, see fzf's README.

 find or fd

You can use the -exec option of find to preview all search results with bat:

bash
find … -exec bat {} +


If you happen to use fd, you can use the -X/--exec-batch option to do the same:

bash
fd … -X bat


 ripgrep

With batgrep, bat can be used as the printer for ripgrep search results.

bash
batgrep needle src/


 tail -f

bat can be combined with tail -f to continuously monitor a given file with syntax highlighting.

bash
tail -f /var/log/pacman.log | bat --p

Top issues

Discussions

Latest release

v0.26.1 v0.26.1 2025-12-02
v0.26.1

 Features

- Add paging to '-h' and '--help' see PR 3478 (@MuntasirSZN)

 Bugfixes

- Fix hang when using --list-themes with an explicit pager, see 3457 (@abhinavcool42)
- Fix negative values of N not being parsed in  line ranges without = flag value separator, see 3442 (@lmmx)
- Fix broken Docker syntax preventing use of custom assets, see 3476 (@keith-hall)
- Fix decorations being applied unexpectedly when piping. Now only line numbers explicitly required on the command line should be applied in auto decorations mode for cat compatibility. See 3496 (@keith-hall)
- Fix di

Snapshot: 2026-11-10T09:35:25Z · Data license Apache-2.0 · JSON