How to colorizing cat command output or files using ccat app on Linux or Unix system

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.

ADVERTISEMENTS

More about ccat

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

Install ccat as per your Linux/Unix distro.

Install ccat on macOS

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

Install ccat on Arch Linux

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.

See also

🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source & DevOps topics via:
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. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.