Open In App

Ccat – Colorize Cat Command Output

Last Updated : 26 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will learn to use the Ccat tool to make our terminal output look good and vibrant.

Ccat is a command line tool that works like the cat command in linux, where the cat is a standard command in linux used for various operations like printing the file content in standard output and concatenating files. But Ccat does something cooler, Ccat uses syntax highlighting by default for its standard output to the terminal, making it look good to see.

Ccat supports popular languages like Java, Javascript, Ruby, JSON, Go, Python, and C.

Installing Ccat:

To install the the Ccat command in your machine follow the specific instructions according to your machine architecture.

For Linux other than Arch-based distributions,

  • Download the latest Ccat package from the Official GitHub release page or use the below command.
wget https://github.com/owenthereal/ccat/releases/download/v1.1.0/linux-amd64-1.1.0.tar.gz



downloading_ccat_ccat_colorize_output_60q

downloading ccat from GitHub release page

  • Extract the tar file using the below command.
tar -xvf linux-amd64-1.1.0.tar.gz


extracting_tar_ccat_colorize_output

extracting tarball of ccat

  • Copy the binary file to the $PATH folder variable such as `/usr/bin` or `/usr/local/bin`.
sudo cp linux-amd64-1.1.0/ccat /usr/bin


copying_binary_ccat_colorize_output

copying binary to /usr/bin

For Arch Linux,

  • Ccat package is available in the Arch User Repository (AUR), use any helpers like yay, paru to install the package.
yay -S ccat

For OSX,

  • Use the brew package manager to install the ccat package.
brew install ccat

For Windows,

  • Download the tar package from the release page according to your machine architecture.
  • Extract the tar into a desired folder.
  • Add the folder to the path variable.

How to View Text file Using Ccat?

To view a single text file, pass the file name as argument to the ccat command.

ccat sample.txt

viewing_single_file_ccat_colorize_output

viewing single text file

How to View multiple files using Ccat?

To view multiple files using ccat, pass the file names as argument one by one. Ccat will print contents every file in order which you have provided. For example:

ccat sample.txt sample2.txt sample3.txt

In this command, ccat' will print the contents of each file in the order you have provided. It sequentially displays the content of file1.txt', followed by afile2.txt, and then file3.txt. This allows you to conveniently examine the contents of multiple files in the same terminal window, providing a quick overview of their content without having to open each file individually. Each file’s content is displayed with syntax highlighting, enhancing readability for various programming languages

viewing_multiple_file_ccat_colorize_output

viewing multiple files

How to view code of any programming language using Ccat?

To view any programming languages code using ccat, pass the file name as argument.

ccat hello.c

  • ccat: This is the command-line tool being used. It is a variant of the traditional cat' command, but with added features such as syntax highlighting.
  • hello.c: This is the argument provided to ccat', specifying the file to be displayed. In this case, it’s assumed that there’s a C programming language source code file named ‘hello.c'.
viewing_syntax_highlighting_ccat_colorize_output

viewing code files

  • Ccat uses its default pallette color to print the code output in the terminal. Incase you want to use a different highlighting colors, you can feel free to do so by passing the required color code parameters.
  • To view the palette color code parameters, use the below command.
ccat --palette

color_palette_ccat_colorize_output

ccat color palette

Now, choose the preferred color for highlighting from that list of colors and map it to the type of content to be colored with that.

ccat -G String=color_code_name -G Keyword=color_code_name file_name


viewing_color_codes_ccat_colorize_output

using custom codes with ccat

How to Display content from the internet using Ccat?

Ccat can also display content from the internet by using pipe with curl command, use the command below.

 curl https://raw.githubusercontent.com/ragul-engg/gfg_potd/main/src/september/FirstSetBit.java | ccat -G String="red" -G Plaintext="brown" -G Keyword="fuchsia"


curl_content_ccat_colorize_output

viewing file from internet with ccat

Viewing output in HTML:

  • Ccat also provides output in the html format. To view the output in html format pass the `–html` flag to the command.

viewing_output_html_ccat_colorizing_output

viewing output in html

  • Viewing HTML file in terminal is not useful, but saving the html and viewing it in a browser will help us to see the ccat –html output visually better.
  • Store the Ccat –html output in a file, and go to the html path in a browser.
  • Here > is used to redirect the stdout to index.html.
ccat filename --html > index.html

creating_output_html_ccat_colorizing_output

creating html output file

viewing_output_html_browser_ccat_colorizing_output

viewing output file in browser

Using Ccat instead of cat:

  • There are numerous features provided by the Ccat package no wonder if you want to use it instead of cat command.
  • To do this create an alias name `cat` and place the path of the Ccat command.
  • So Ccat command will be triggered whenever you use cat command in your terminal.
  • Open your .bashrc file under your user home directory.
  • Add the below lines in the file to create the alias.
alias cat=/usr/bin/cat

  • Reload the bash with the source command.
source $HOME/.bashrc

  • Now the ccat command will be used, even if you use cat command in the terminal.

aliasing_ccat_ccat_colorize_output

a

Getting Help in Cat:

To get help and view the options available in ccat, use the –help flag with cccat.

ccat --help

ccat_help_ccat_colorize_output

ccat help command

Conclusion:

In summary, Ccat stands out as a powerful replacement for the conventional cat' command on Linux. Its ability to provide syntax highlighting for various programming languages, customizable color coding, and support for HTML output elevate the command-line experience. The straightforward installation process, compatibility with different operating systems, and the option to create an alias for ‘cat' make Ccat a valuable addition to the Linux toolset. Users can enjoy enhanced readability, comprehension, and visual appeal when viewing files, snippets from the internet, or even creating HTML-formatted content. Embracing Ccat enriches the terminal usage with an aesthetically pleasing and feature-rich alternative to the traditional cat command.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads