代码之家  ›  专栏  ›  技术社区  ›  DavidWinterbottom

哪些UNIX命令支持彩色输出?

  •  11
  • DavidWinterbottom  · 技术社区  · 16 年前

    那些在我的 ~/.bash_aliases

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

    5 回复  |  直到 16 年前
        1
  •  9
  •   paxdiablo    16 年前

    man -K color
    

    这应该在你的所有手册页(内容,而不仅仅是标题)中搜索单词颜色。

    $ 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
    
    $
    

    /color<ENTER>

        2
  •  8
  •   David Dean    16 年前

    快速谷歌搜索也揭示了 grc grcat ,可用于为任何任意文本或命令着色。但不确定它们有多好。既然我已经找到了,我肯定会尝试一下。

    啊,我们开始吧。 希腊语 使用 /etc/grc.conf 文件,用于根据匹配的正则表达式对给定命令进行着色。我的快速grep(Ubuntu 8.10) /etc/grc.conf 显示它目前支持:

    [~]$ 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
    

    使用 希腊语 ,只需将其放在要着色的命令之前(比如 diff ):

    grc diff foo.txt bar.txt
    

    alias diff='grc diff' 使成为…… 差异

        3
  •  3
  •   David Dean    16 年前
        4
  •  0
  •   anon anon    16 年前

    #!/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
    
        5
  •  0
  •   Philip Durbin    16 年前

    在查看日志时,您可能会喜欢 tail -f /var/log/messages | loco 用于彩色输出。

    有一个 screenshot loco 网站和更多示例 http://www.linuxhaxor.net/2008/01/02/perl-script-to-add-nice-colors-to-your-varlogmessages-file