Open In App

Ccat – Colorize Cat Command Output command in Linux with Examples

Last Updated : 13 Nov, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

ccat is a Linux and macOS cat command that improved its precursor: the syntax highlighted file contents can be displayed with its help. Therefore, in the case of source code and configuration files, it is extremely helpful. It can highlight over 10 languages, like JavaScript, Java, Ruby, Python, Go, C, and JSON.

Syntax

ccat [OPTIONS] [FILE...]

Basic Usage

The most straightforward way to use ccat is to view the contents of one file with highlighting:

ccat code.cpp
2024-10-25_16-56_1
Terminal showing CPP code with keywords, strings, and comments colored in different colors

Command Options and Features for the Colorize Cat Command

Option

Description

Example

--bg=MODE

Set background mode (dark/light)

ccat --bg=dark file.py

--palette

Show color palette

ccat --palette

--html

Output in HTML format

ccat --html file.cpp

--color=WHEN

When to use colors (always/never/auto)

ccat --color=always file.js

Installing ccat

On macOS:

brew install ccat

On Linux:

Prerequisites:

  • Git
  • Go 1.4+

Installation command:

go install github.com/owenthereal/ccat@latest

Example Advanced Use Cases

1. Printing Many Files

ccat index.css index.js index.ts
2024-10-25_17-01
Terminal output of many files with syntax highlighted clearly distinguished

2. Dark Theme With a Personal Color Scheme

ccat --bg=dark --color=always code.cpp
2024-10-25_17-03
Terminal output of C++ with dark background, but bright syntax highlighting

3. HTML Output Generation

ccat --html index.js > highlighted.html
2024-10-25_17-06
Browser view of JavaScript code with HTML format applied to the syntax highlighting

Code Review Script Practical Example

#!/bin/bash
# Code review script reading syntax-highlighted changed files in a git repository

for file in $(git diff --name-only HEAD~1); do
echo "=== Reviewing: $file ==="
ccat --bg=dark "$file"
echo "======================="
read -p "Press Enter to continue."
done

Conclusion

Syntax highlighting and several display options are added to upgrade the code reading experience of ccat. This is very helpful for developers who view code in the terminal quite frequently since they are going to find better readability in comparison with the standard cat command. With several programming language support and customizable display options, ccat is a highly effective tool for both development and system administration tasks.


Similar Reads