All Posts programming show file content | bat cheat-sheet

show file content | bat cheat-sheet

Β· 246 words Β· 2 minute read

What is bat ? πŸ”—

Print and concatenate files. A cat clone with syntax highlighting and Git integration.

Common usage patterns πŸ”—

Pretty print the contents of one or more files to the standard output (a.k.a. stdout):

bat path/to/file1 path/to/file2 ...

Concatenate several files into the target file:

bat path/to/file1 path/to/file2 ... > path/to/target_file

Remove decorations and disable paging (--style plain can be replaced with -p, or both options with -pp):

bat --style plain --pager never path/to/file

Highlight a specific line or a range of lines with a different background color:

bat [-H|--highlight-line] 10|5:10|:10|10:|10:+5 path/to/file

Show non-printable characters like space, tab or newline:

bat [-A|--show-all] path/to/file

Remove all decorations except line numbers in the output:

bat [-n|--number] path/to/file

Syntax highlight a JSON file by explicitly setting the language:

bat [-l|--language] json path/to/file.json

Display all supported languages:

bat [-L|--list-languages]

Notes πŸ”—

  • bat is distributed as batcat via APT package manager. Why?

Here is the answer:

In this package the executable and its manpage have been renamed from β€˜bat’ to β€˜batcat’ because of a file name clash with another Debian package.

bat renamed to batcat

I hope you enjoyed reading this post as much as I enjoyed writing it. If you know a person who can benefit from this information, send them a link of this post. If you want to get notified about new posts, follow me on YouTube , Twitter (x) , LinkedIn , and GitHub .