Ccat – Colorize Cat Command Output

As you might already know, Cat, acronym for concatenate, is an Unix command to view, combine, and copy text files. This command is one of the most frequently used command everyday in GNU/Linux and Unix-like operating systems. If you use cat command often, you might want to try ‘Ccat’. It is very similar to cat command, but displays the contents with syntax highlighting. The currently supported languages are JavaScript, Java, Ruby, Python, Go, C, and JSON.

Installing Ccat

Ccat is available in AUR, so you can install it using any AUR helpers in Arch Linux and its variants.

Using Pacaur:

pacaur -S ccat

Using Packer:

packer -S ccat

Using Yaourt:

yaourt -S ccat

Using Yay:

yay -S ccat

On other Linux distributions, you need to compile and install Ccat as shown below.

Download the latest ccat binary from here.

wget https://github.com/jingweno/ccat/releases/download/v1.1.0/linux-amd64-1.1.0.tar.gz

Extract the downloaded archive file:

tar xfz linux-amd64-1.1.0.tar.gz 

Copy the ccat executable file to your bin folder to use system wide:

sudo cp linux-amd64-1.1.0/ccat /usr/local/bin/

Finally, make it executable using command:

sudo chmod +x /usr/local/bin/ccat

Usage

The usage is very similar to cat command. Let me show you some examples.

To view a text file, for example test.txt, using cat command, we use:

cat test.txt

Now, view the text file with “ccat”.

ccat test.txt

Did you notice the difference? ccat displays the output with syntax highlighting whereas cat command simply displays output in the system’s default theme color.

We can also display the output of multiple files (i.e concatenate) at once like below.

ccat test.txt example.txt

For some reason, you may want to display the output in HTML format. To do so, just add “–html” option at the end.

ccat test.txt --html

Not just local files, we can also directly display the contents of a file in the web like below.

curl https://raw.githubusercontent.com/jingweno/ccat/master/main.go | ccat

To view the default applied color codes, run

ccat --palette

You can, of course, set your own color codes like below.

ccat -G String="_fuchsia_" -G Plaintext="darkteal" test.txt

If you like ccat and wanted to replace the default cat command, just create an alias.

If you installed it from AUR in Arch Linux, add the following line in your ~/.bashrc file.

alias cat=ccat

If you installed it from the compiled binary file, add the following line in ~/.bashrc file.

alias cat='/usr/local/bin/ccat

Finally, run the following command to take effect the changes.

source ~/.bashrc

To add it system wide, add the above entry in /etc/bashrc (On RPM based systems) or /etc/profile (on Debian based systems) file.

And, that’s all for now. Hope this helps. More good stuffs to come. Stay tuned!

Cheers!

Resource:

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *