The cat command (short for concatenate) is one of the most frequently used flexible commands on Linux, Apple MacOS X, *BSD (FreeBSD / OpenBSD / NetBSD), Unix-like operating systems. It is useful to display text files on screen, copy text files, combine text files, create new text files and more. If you cat command with colours, try ccat app.
More about ccat command that can colorizing cat command output
ccat is the colorizing cat. It works similar to the cat command but displays content with syntax highlighting. It supports JavaScript, Java, Ruby, Python, Go, C, and JSON programming languages. The overhead of ccat command comparing to a cat is minimum on a modern desktop with powerful multi-core CPUs and tons of RAM.
Installation
We can nnstall ccat as per our Linux/Unix distro. Let us get started.
Install ccat on macOS
First, install Homebrew on macOS and then type the following brew command:
$ brew install ccat
Sample outputs:
==> Downloading https://homebrew.bintray.com/bottles/ccat-1.1.0.sierra.bottle.tar.gz ######################################################################## 100.0% ==> Pouring ccat-1.1.0.sierra.bottle.tar.gz 🍺 /usr/local/Cellar/ccat/1.1.0: 4 files, 3.5MB
Arch Linux install ccat /h3>
Type the following command:
$ sudo pacaur -S ccat
Generic installation method for Linux/Unix users
You must have golang installed on your system. Type the following command
$ go get -u github.com/jingweno/ccat
How do I use ccat command?
The syntax is as follows:
$ ccat fileNameHere
$ ccat /etc/passwd
$ ccat file.txt foo.txt bar.txt
To output in HTML
$ ccat --html file.txt
Set dark background
$ ccat --bg=dark input.txt
Set light background:
$ ccat --bg=light input.txt
You can set color codes too:
$ ccat -G String="_darkblue_" -G Plaintext="darkred" input
To see all possible values for color codes/palette run:
$ ccat --palette
Sample outputs:
Applied color codes: String brown Keyword darkblue Comment lightgrey Type teal Literal teal Punctuation darkred Plaintext darkblue Tag blue HTMLTag lightgreen HTMLAttrName blue HTMLAttrValue green Decimal darkblue Color code is in the format of: color normal color *color* bold color _color_ underlined color +color+ blinking color Value of color can be black, blink, blue, bold, brown, darkblue, darkgray, darkgreen, darkred, darkteal, darkyellow, faint, fuchsia, fuscia, green, lightgray, overline, purple, red, reset, standout, teal, turquoise, underline, white, yellow
You can read input from stdin/keyboard as follows:
$ ccat
You need to press [CTRL] + [D] i.e. hold the control key down, then tap d to exit ccat session:
$ curl https://raw.githubusercontent.com/nixcraft/pf.conf/master/pf.conf | ccat
Sample outputs:
For more info see ccat project home page.
Conclusion
You learned how to colorize the cat command outputs using ccat. See the following links for more on the cat command:
- remark Command: How to color syslog file as well as output of of programs such as ping, traceroute, and much more.
- bat Linux command – A cat clone with written in Rust
🐧 2 comments so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Still not available on fedora repos :/
I use Pygmetize
> cat [some-file] | pygmentize -O style=monokai -g
or create a bash script called ccat
> #!/usr/bin/env bash
> pygmentize -O style=monokai -g $1