What Is It?
I recently learned about the
bat command available on Linux and wanted to share it in case it was useful to anyone else. If you’re like me and you find it easier to read log and config files when they have syntax highlighting
bat might be for you, it’s a drop in replacement for
In addition to syntax highlighting
bat also adds line numbers and has options for various additional features like running a git diff, choosing a specific line range or highlighting a particular line number.
Show only lines that have been added/removed/modified according to git:
bat -d app.js
Show only lines 20-30:
bat -r 20:30 app.js
Highlight line 28 in the output:
bat -H 28 app.js
Tailing / Watching A File
The one thing that’s missing from
bat is a tail/watch option (something equivalent to
tail -f) that’s not a complete surprise as bat is intended as a drop in replacement for
cat which just echos files to standard output. However since this is a common use case when looking at log files you might also want to look at
grc which is a generic colouriser for Linux.
The idea with
grc is that you can still use the commands you’re familiar with like
cat but pass them into
grc for syntax highlighting, it’s not as good as
grc tail -f /var/log/nginx/access.log
You’ll probably be able to find both in your package manager but in case you can’t or you want more info here are the links to the GitHub repositories: