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:

Fig.01: ccat command in action

You can read source directly from the web too:
$ curl https://raw.githubusercontent.com/nixcraft/pf.conf/master/pf.conf | ccat
Sample outputs:

Fig.02: ccat command in action

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:


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 2 comments so far... add one

CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
2 comments… add one
  • Amitosh Sep 2, 2017 @ 10:30

    Still not available on fedora repos :/

  • Me Sep 15, 2017 @ 10:38

    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

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @ webmaster@cyberciti.biz