The cat command on Linux concatenates files together. It's often used to concatenate one file to nothing to print the single file's contents to the terminal. This is a quick way to preview the contents of a text file without having to open the file in a large application.
There's nothing wrong with cat, but similar commands have been developed over the years, and the one with the most features is bat.
[ Keep your most commonly used commands handy with the Linux commands cheat sheet. ]
Syntax highlighting
Developers call bat, available under the terms of either the MIT License or the Apache License 2.0 (your choice), a "cat clone with wings." There's probably a healthy debate over what those wings are, but for me, it's the syntax highlighting and line numbering. It's a highly visual feature and can be a great help when scanning through files.
Because you're likely to use the bat output as the input for a second command, you can deactivate extra data like line numbers with the --plain option. Supported terminals retain syntax highlighting.
The --plain option is an alias for --style=plain, which hints at just how many ways you can customize the command's output. Here are some of my favorite options for the --style option:
- plain: Include no style that adds extra characters to the output
- header: Print the file name before the file's contents
- header-filesize: Print the file size before the file's contents
- grid: Add grid lines to separate output
- numbers: Print line numbers
That's not all of the style options, just the ones I use frequently.
[ Keep your favorite Git commands, aliases, and tips close at hand. Download the Git cheat sheet. ]
Git integration
Did I say syntax highlighting was my favorite feature? I meant that Git integration is my favorite feature. The bat command is Git-aware by default. When you're in a Git repository, you can use the --diff option to view just the changes to a file since it was last committed.
For instance, imagine I'm in the Git repository of my zombie apocalypse game. I've recently updated some code, but I can't quite recall the extent of it.
$ bat --diff Zombie.java
1 public class Player {
2
3 private BufferedImage image;
4+ private Position pos;
5 private Health health;
6-
7 public Zombie() {
8 loadImage();
[...]
When a line has been added since the previous commit, a plus sign (+) appears in the margin, and when a line has been changed or removed, a minus sign (-) appears.
The --diff option works only with Git. It's not a general-purpose diff tool.
[ Learn how to manage your Linux environment for success. ]
Highlight arbitrary lines
You can highlight a range of lines in a file. This isn't syntax highlighting, which bat does automatically. Instead, this marks each line with a solid box, as if to mimic a highlighter you use on paper.
$ bat --highlight-line=20:26 ZombieCruncher.java
Your results may vary with this effect. On some screens, I have a feeling that instead of highlighting, this effect obfuscates due to a drop in contrast. Still, it's a visual marker that might be useful to some.
Install bat
There are more features in bat than what I've covered here, but these are the ones I use the most. The bat command isn't strictly essential. Commands like cat and more, and even sed or awk in a pinch, perform basically the same function, but bat consciously does it with a lot more style. And that counts for something, if you like the visual aid of colorful output and a little extra context.
To install bat on Fedora, use the package manager:
$ sudo dnf install bat
On other systems, you can download a binary release from the bat Git repository or build it using the crate command.
저자 소개
Seth Kenlon is a Linux geek, open source enthusiast, free culture advocate, and tabletop gamer. Between gigs in the film industry and the tech industry (not necessarily exclusive of one another), he likes to design games and hack on code (also not necessarily exclusive of one another).
유사한 검색 결과
More than meets the eye: Behind the scenes of Red Hat Enterprise Linux 10 (Part 5)
Announcing general availability of SQL Server 2025 on Red Hat Enterprise Linux 10
The Overlooked Operating System | Compiler: Stack/Unstuck
Linux, Shadowman, And Open Source Spirit | Compiler
채널별 검색
오토메이션
기술, 팀, 인프라를 위한 IT 자동화 최신 동향
인공지능
고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트
오픈 하이브리드 클라우드
하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요
보안
환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보
엣지 컴퓨팅
엣지에서의 운영을 단순화하는 플랫폼 업데이트
인프라
세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보
애플리케이션
복잡한 애플리케이션에 대한 솔루션 더 보기
가상화
온프레미스와 클라우드 환경에서 워크로드를 유연하게 운영하기 위한 엔터프라이즈 가상화의 미래