If you use the Linux operating system (or Unix), you've probably used 'cat' - a part of the GNU core utilities (coreutils) package. The cat command concatenates and displays file content, perfect for quickly viewing or merging files.
In 2016, David Peter (Sharkdp) created 'bat' - a clone of cat, but with enhancements that include syntax highlighting, Git integration, and line numbers, creating a more advanced and user-friendly alternative. Let's get it set up in WSL.
Download the latest release of 'bat'
curl LO https://github.com/sharkdp/bat/releases/download/v0.19.0/bat-v0.19.0-x86_64-unknown-linux-musl.tar.gz
Extract the tar
tar -xzf bat-v0.19.0-x86_64-unknown-linux-musl.tar.gz
Move the binary to /usr/bin
sudo mv bat-v0.19.0-x86_64-unknown-linux-musl/bat /usr/bin/
Make the binary executable
sudo chmod +x /usr/bin/bat
Verify installation
bat --version
Test bat with file
bat ~/.bashrc
For bat to show syntax highlighting, the file needs to contain recognized patterns for a specific language or format - ie - Keywords and Commands / Variables / File Extensions / Shebang Lines / Etc
Highlighting works best with structured code or configuration files. General text might not show much highlighting. So, bat is perfect for code and scripts but might be overkill for plain text.
Line numbers in bat are enabled by default. Toggle them with the --number flag if they’re not showing:
bat --number <filename>
Ben Santora - October 2024
Top comments (0)