A colorful cat under Linux

A colorful cat under Linux

Friends who have used the Linux system must have used the cat command. Of course, under Linux, this cat is not that cat. The cat here does not mean cat, but is the abbreviation of the word concatenate.

The cat command is a text viewing command under Unix or Unix-like systems. It can also be used with redirection to achieve merging and copying functions. It is one of the most commonly used commands in GNU Linux and Linux-like operating systems and is used very frequently.

But for programmers, the problem with cat command is that its output does not have any color marking. If we use the cat command to view the code file, it is really inconvenient to read without color marking of keywords.

In order to solve this pain point, a big guy developed the ccat command. ccat is very similar to cat , but when using the ccat command, the code content displayed will be colored, which is very friendly to programmers. Currently, ccat supports JavaScript, Java, Ruby, Python, Go, C and JSON languages.

The following is a detailed introduction to the usage of ccat.

1. Install Ccat

1) ccat command is directly available in AUR, so if you have AUR helper in your system, you can directly install it. For example, on the Arch system, you can install it directly using the yay command.

Arch User Repository is commonly referred to as AUR. AUR Helper is a wrapper that allows users to install packages from the AUR repository without manual intervention.

$ yay -S ccat

2) In other Linux distributions, you need to compile and install ccat, the steps are as follows:

Use the following command to download the source archive compressed package

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

Unzip the downloaded archive

$ tar xfz linux-amd64-1.1.0.tar.gz

Copy the ccat executable to your system $PATH (e.g., /usr/local/bin/)

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

Finally, use chmod to add executable permissions for the ccat command

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

2. How to use ccat to colorize the cat command

The usage of ccat is very similar to the cat command. Here are some examples.

Let's first use the cat command to view a text file, such as hello.c.

$ cat hello.c

The effect is as follows

You can see that the code does not have any color marking (this result should be familiar to everyone). Now, use ccat again to view the text file hello.c and see how it displays the output.

$ ccat hello.c

The effect is as follows:

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

We can also display the output of multiple files at a time as shown below.

$ ccat test.txt example.txt

For some reasons, you may want to display the output in HTML format. To do this, just add the “--html” option to the end.

$ ccat test.txt --html

Not only local files, we can also display the contents of files directly on the network as shown below.

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

To see the default code coloring, run the following command.

$ ccat --palette

Of course, you can set your own color code as follows.

$ ccat -G String="_fuchsia_" -G Plaintext="darkteal" hello.c

ps: You may encounter the following errors during the download step

This is because GitHub upgraded OpenSSL and disabled TLSv1.1. You only need to update the local OpenSSL and Git tools to solve the problem.

3. Replace cat in the system

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

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

alias cat=ccat

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

alias cat=/usr/local/bin/ccat

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

$ source ~/.bashrc

To add it system-wide (all users can use this command), add the above entry in /etc/bashrc (on RPM based systems) or /etc/profile (on Debian based systems) file.

This is the end of this article about a colorful "cat" under Linux. For more relevant content on the usage of linux ccat, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

<<:  How to implement scheduled backup of CentOS MySQL database

>>:  Examples of using provide and inject in Vue2.0/3.0

Recommend

The basic use of html includes links, style sheets, span and div, etc.

1. Links Hypertext links are very important in HTM...

33 of the best free English fonts shared

ChunkFive Free Typefamily Cuprum JAH I Free font Y...

Improving the effect of hyperlinks in web design and production

Hyperlinks enable people to jump instantly from pa...

Bug of Chinese input garbled characters in flex program Firefox

Chinese characters cannot be input in lower versio...

Five ways to traverse objects in javascript Example code

Table of contents Prepare Five weapons for…in Obj...

MySQL-group-replication configuration steps (recommended)

MySQL-Group-Replication is a new feature develope...

Detailed tutorial on using VMware WorkStation with Docker for Windows

Table of contents 1. Introduction 2. Install Dock...

Mysql timeline data to obtain the first three data of the same day

Create table data CREATE TABLE `praise_info` ( `i...

XHTML Getting Started Tutorial: What is XHTML?

What is HTML? To put it simply: HTML is used to m...

In-depth understanding of the vertical-align property and baseline issues in CSS

vertical-align attribute is mainly used to change...

Explanation of the usage of replace and replace into in MySQL

MySQL replace and replace into are both frequentl...

CSS Viewport Units for Fast Layout

CSS Viewport units have been around for the past ...

Example of how to configure the MySQL database timeout setting

Table of contents Preface 1. JDBC timeout setting...