What UNIX commands support coloured output?

馋奶兔 提交于 2019-12-02 23:43:13

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.

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.

I'm quite fond of coloring my prompt so that it stands out. A useful article on that sort of thing is available here.

This demo bash script colours directories red in most terminals - certainly works in xterms and cygwin under Windows. You can adapt the colours by fiddling with the escape codes - Google for LS_COLOR for lists of colour codes:

#!/bin/bash

color_red()
{
    echo -e "\033[01;31m$1\033[00m"
}

for FILE in $*
do
    if test -d $FILE
    then
        color_red $FILE
    else
        echo $FILE
    fi
done

When looking at logs, you might enjoy tail -f /var/log/messages | loco for colorized output.

There's a screenshot at the loco website and more examples at http://www.linuxhaxor.net/2008/01/02/perl-script-to-add-nice-colors-to-your-varlogmessages-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!