【问题标题】:Further customizing coloring using aliases, ls, and dircolors in .bashrc file使用 .bashrc 文件中的别名、ls 和 dircolors 进一步自定义着色
【发布时间】:2014-10-29 20:31:25
【问题描述】:

ls man page--colors 标志当然是解释的,并且在页面底部提到了使用dir_colors 可以进行进一步定制的想法。我进一步发现了一些有用的页面written by others who have used dir_colors,但不足以让我一路找到我正在寻找的答案。

我想问的是:

我需要将什么附加到 .bashrc 文件以使具有给定扩展名的文件以给定颜色显示?

举个例子,我怎样才能让所有 .sh 文件都显示为橙色?还是所有 .tar.gz 文件都显示为红色?

【问题讨论】:

    标签: linux colors alias ls


    【解决方案1】:

    没有橙色:-)

    这是我的 ~/.dir_colors 的点点滴滴(多年前继承的) 由 .bashrc 中的 eval dircolors ~/.dir_colors 加载:

    # Below are the color init strings for the basic file types. A color init
    # string consists of one or more of the following numeric codes:
    # Attribute codes: 
    # 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
    # Text color codes:
    # 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
    # Background color codes:
    # 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
    NORMAL 00       # global default, although everything should be something.
    FILE 00         # normal file
    DIR 01;34       # directory
    LINK 01;36      # symbolic link
    FIFO 40;33      # pipe
    SOCK 00;35      # socket
    BLK 40;33;01    # block device driver
    CHR 40;33;01    # character device driver
    ORPHAN 01;05;37;41  # orphaned syminks
    MISSING 01;05;37;41 # ... and the files they point to
    # This is for files with execute permission:
    EXEC 01;32 
    

    然后是 .sh 和 .gz:

    .sh  01;32 # executable in bold green
    .csh 01;32
    .tar 01;31 # archives or compressed (bright red)
    .tgz 01;31
    .arj 00;31
    .taz 01;31
    .lzh 00;31
    .rar 01;31
    .RAR 01;31
    .zip 01;31
    .ZIP 01;31
    .z   01;31
    .Z   01;31
    .gz  01;31
    .bz2 01;31
    .bz  01;31
    .tz  01;31
    .jar 01;31
    .rpm 01;31
    .deb 01;31
    .cpio 01;31
    .iso 01;31
    .ISO 01;31
    

    至于橙色,也许黄色就足够了?

    .sh  01;33 # shell in bold yellow
    

    【讨论】:

    • 这回答了提问者的例子,但不是他们的问题。解释为什么答案会更好:01;33 是什么意思?
    • /Why?/ 不是一个有效的问题。如果你想知道 /how/,那么请阅读代码中的 cmets,特别是关于属性代码和文本颜色代码的内容。还有 /dircolor/ 的手册,不要忘记你的操作系统内核的来源。
    猜你喜欢
    • 2013-10-11
    • 1970-01-01
    • 2022-10-06
    • 2021-09-24
    • 2021-02-24
    • 2019-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多