Ccat, colors the output of the cat command in the terminal

about cat

In the next article we are going to take a look at ccat. I think that by most users it is known that the cat command. It is a Unix command to view, combine and copy text files. This is possibly one of the most used commands by everyday users on GNU / Linux and Unix operating systems.

If you are one of those users who uses cat often, you may be interested in ccat. Is about a command very similar to the cat command. Its function is basically the same, but ccat will show us the contents with syntax highlighting, which can be very convenient when reading code. The supported languages ​​for syntax highlighting are: JavaScript, Java, Ruby, Python, Go, C, and JSON.

Ccat installation on Ubuntu

To be able to use this command in our Ubuntu system, we are only going to have to download the latest version published, a while ago, from ccat from his GitHub page. If you prefer to use the terminal (Ctrl + Alt + T) to download the package, you just have to type in it:

download ccat with wget

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

At the end of the download, extract the downloaded compressed file. In the same terminal, you just have to write:

tar xfz linux-amd64-1.1.0.tar.gz

Now we are going to copy the executable file ccat to your $ PATH, as it would be for example / usr / local / bin /. To do this we write the command:

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

In conclusion, let's make it executable using the following command in the same terminal:

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

Using ccat

If you use this command, you will see that the use is very similar to that of the cat command. Next we are going to see some basic examples.

If we use the cat command to view a text file, such as test.txt, we will use the command as follows:

example cat ccat

cat prueba.txt

Now let's see as ccat shows us the output from the same file. You just have to write in the same terminal:

example ccat test

ccat prueba.txt

As you can see in the above screenshots, ccat will show us the output with syntax highlighting. While the command cat displays the output using your system's default theme color.

Show the output of multiple files

We will also be able to see the output of several files at the same time, as can be seen in the following screenshot:

ccat showing two files

ccat prueba.txt ccat.txt

View the output in HTML format

If for any reason you are interested in seeing the output in HTML format, you can do it easily adding the option "-html”At the end of the command:

ccat html output

ccat prueba.txt --html

View the content of an internet file

We will not only be able to see the local files with this command. We will also have the possibility of directly view the content of a file on a web using the curl command, as you can see below:

internet ccat file

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

Set color codes

For view the default applied color codes and available options, we will only have to execute:

ccat color palette

ccat --palette

Of course, we will be able to configure our own color codes on a file using the following command in terminal:

change ccat output color

ccat -G String="darkteal" -G Plaintext="green" -G Keyword="fuchsia" prueba.txt

Replace cat with ccat

If you like ccat and you think it can be useful, you might be interested replace the default cat command with ccat. To carry out the replacement, we will only have create an alias.

To create the alias, we will only have to add the following line in ~ / .bashrc file:

create alias ccat

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

Once the file is saved, all you have to do is run the following command to make the changes effective:

source ~/.bashrc

If you are interested know more about how to create aliases, you can consult more in the article written on Wikipedia.

Help

It can be obtained help on how to use this command typing in the terminal:

ccat help

ccat -h

You can also know more about this command checking the project's GitHub page.


Leave a Comment

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

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.