Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What UNIX commands support coloured output?

I enjoy using UNIX/bash commands that support coloured output. Consequently, I have a few aliases defined which automatically enable coloured output of the commands that I know support this option. However, I'm sure there are hundreds of commands out there that support coloured output - I'd like to know what they are.

The ones in my ~/.bash_aliases file are:

ls --color=auto
grep --color
phpunit --ansi

What else is there? Is there a list somewhere of all commands that support coloured output? Or better still, some command for grepping my local man pages and plucking out the appropriate command names.

like image 466
DavidWinterbottom Avatar asked Feb 19 '09 00:02

DavidWinterbottom


People also ask

How do you grep with color?

The —-color parameter tells grep to color the search terms in the output, which helps them stand out when among all the other text on the line. You choose which color you want using the GREP_COLOR environment variable: export GREP_COLOR=36 gives you cyan, and export GREP_COLOR=32 gives you lime green.

How do I add color to a bash script?

This can be accomplished by adding a \e at the beginning to form an escape sequence. The escape sequence for specifying color codes is \e[COLORm (COLOR represents our color code in this case). By default, echo does not support escape sequences. We need to add the -e option to enable their interpretation.


2 Answers

Why don't you try:

man -K color

That should search for the word color in all your man pages (content, not just headings).

It asks, for each man page, whether you want to open and view the page:

$ man -K color
/usr/share/man/mann/Widget.n.gz? [ynq] y
/usr/share/man/mann/usual.n.gz? [ynq] y
/usr/share/man/mann/Toplevel.n.gz? [ynq] n
/usr/share/man/mann/itk.n.gz? [ynq] n
/usr/share/man/mann/Archetype.n.gz? [ynq] n
/usr/share/man/man8/squid.8.gz? [ynq] n
/usr/share/man/man7/Xprint.7.gz? [ynq]
/usr/share/man/man7/X.7.gz? [ynq]
/usr/share/man/man7/urxvt.7.gz? [ynq]
/usr/share/man/man7/term.7.gz? [ynq] q

$

Inside each individual man page, you can use your normal search method (e.g., /color<ENTER>) for finding the text. When done with a man page, just exit and it will continue searching.

like image 109
paxdiablo Avatar answered Oct 21 '22 04:10

paxdiablo


A quick bit of google search also reveals grc and grcat, which can be used to colorise any arbitrary text or command. Not sure how well they work though. I'm certainly going to try them out now that I've found them.

Ah, here we go. grc uses the /etc/grc.conf file to colorise a given command based on which regexp it matches. A quick grep of my (Ubuntu 8.10) /etc/grc.conf reveals it currently has support for:

[~]$ less /etc/grc.conf | grep '^#'
# anything to do with irc
# log file
# ping command
# traceroute command
# gcc command
# make command
# netstat command
# diff command
# last command
# ldap tools
# cvs command

But I'm sure you could add your own for other programs you are interested in.

To use grc, simply put it before the command you want to colorise (lets say diff):

grc diff foo.txt bar.txt

And you could certainly alias diff='grc diff' to make diff colorised by default.

like image 27
David Dean Avatar answered Oct 21 '22 05:10

David Dean