使用xshell securecrt 时,可以自定义颜色主题文件, 但是各个颜色块都代表什么意思呢?
搜索linux下文件颜色的含义,也没看到一个讲清楚的,比如说

蓝色表示目录;绿色表示可执行文件;红色表示压缩文件;浅蓝色表示链接文件;白色表示其他文件;黄色是设备文件,包括block, char, fifo。

但是内部原理是什么呢?现在想要改变xshell中目录的显示颜色,在ASNI颜色设置中 ,总共有16个颜色块, 哪一个代表目录的颜色呢?

如图
xshell ASNI配置

ASNI定义了几种基本颜色的编码

  1. Black: \u001b[30m.
  2. Red: \u001b[31m.
  3. Green: \u001b[32m.
  4. Yellow: \u001b[33m.
  5. Blue: \u001b[34m.
  6. Magenta: \u001b[35m.
  7. Cyan: \u001b[36m.
  8. White: \u001b[37m.
  9. #30(黑色)、31(红色)、32(绿色)、 33(黄色)、34(蓝色)、35(洋红)、36(青色)、37(白色)

下面是个人理解, 有问题请指出
第一行每一个色块分别对应上面的8个编码,第二行分别对应加粗字体。

30颜色对应第一个色块, 37颜色对应第8个色块
例如, 把第一行第二个色块,改为白色,表示 31 编码的颜色,在xshell中将显示为白色。

第三方工具的设置ASNI颜色, 本质上就是把预定好这八种颜色,显示为其他颜色。
如果某个文件,颜色类型为39, 超出了这八种基本颜色,则显示为原本编码好的ASNI颜色


  1. ln@ln-PC:~/1src/shell$ dircolors -p
  2. # Configuration file for dircolors, a utility to help you set the
  3. # LS_COLORS environment variable used by GNU ls with the --color option.
  4. # Copyright (C) 1996-2017 Free Software Foundation, Inc.
  5. # Copying and distribution of this file, with or without modification,
  6. # are permitted provided the copyright notice and this notice are preserved.
  7. # The keywords COLOR, OPTIONS, and EIGHTBIT (honored by the
  8. # slackware version of dircolors) are recognized but ignored.
  9. # Below are TERM entries, which can be a glob patterns, to match
  10. # against the TERM environment variable to determine if it is colorizable.
  11. TERM Eterm
  12. TERM ansi
  13. TERM *color*
  14. TERM con[0-9]*x[0-9]*
  15. TERM cons25
  16. TERM console
  17. TERM cygwin
  18. TERM dtterm
  19. TERM gnome
  20. TERM hurd
  21. TERM jfbterm
  22. TERM konsole
  23. TERM kterm
  24. TERM linux
  25. TERM linux-c
  26. TERM mlterm
  27. TERM putty
  28. TERM rxvt*
  29. TERM screen*
  30. TERM st
  31. TERM terminator
  32. TERM tmux*
  33. TERM vt100
  34. TERM xterm*
  35. # Below are the color init strings for the basic file types. A color init
  36. # string consists of one or more of the following numeric codes:
  37. # Attribute codes:
  38. # 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
  39. # Text color codes:
  40. # 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
  41. # Background color codes:
  42. # 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
  43. #NORMAL 00 # no color code at all
  44. #FILE 00 # regular file: use no color at all
  45. RESET 0 # reset to "normal" color
  46. DIR 01;34 # directory
  47. LINK 01;36 # symbolic link. (If you set this to \'target\' instead of a
  48. # numerical value, the color is as for the file pointed to.)
  49. MULTIHARDLINK 00 # regular file with more than one link
  50. FIFO 40;33 # pipe
  51. SOCK 01;35 # socket
  52. DOOR 01;35 # door
  53. BLK 40;33;01 # block device driver
  54. CHR 40;33;01 # character device driver
  55. ORPHAN 40;31;01 # symlink to nonexistent file, or non-stat\'able file ...
  56. MISSING 00 # ... and the files they point to
  57. SETUID 37;41 # file that is setuid (u+s)
  58. SETGID 30;43 # file that is setgid (g+s)
  59. CAPABILITY 30;41 # file with capability
  60. STICKY_OTHER_WRITABLE 30;42 # dir that is sticky and other-writable (+t,o+w)
  61. OTHER_WRITABLE 34;42 # dir that is other-writable (o+w) and not sticky
  62. STICKY 37;44 # dir with the sticky bit set (+t) and not other-writable
  63. # This is for files with execute permission:
  64. EXEC 01;32
  65. # List any file extensions like \'.gz\' or \'.tar\' that you would like ls
  66. # to colorize below. Put the extension, a space, and the color init string.
  67. # (and any comments you want to add after a \'#\')
  68. # If you use DOS-style suffixes, you may want to uncomment the following:
  69. #.cmd 01;32 # executables (bright green)
  70. #.exe 01;32
  71. #.com 01;32
  72. #.btm 01;32
  73. #.bat 01;32
  74. # Or if you want to colorize scripts even if they do not have the
  75. # executable bit actually set.
  76. #.sh 01;32
  77. #.csh 01;32
  78. # archives or compressed (bright red)
  79. .tar 01;31
  80. .tgz 01;31
  81. .arc 01;31
  82. .arj 01;31
  83. .taz 01;31
  84. .lha 01;31
  85. .lz4 01;31
  86. .lzh 01;31
  87. .lzma 01;31
  88. ... etc

举例分析
DIR 01;34 # directory
定义了目录文件使用 34 编码, 在标准终端中, 显示颜色是蓝色

现在想要目录在xshell中的显示为绿色,由于目录颜色为34编码,对应第5个色块(30对应第一个色块), 则在ASNI设置中点击 第一行第五个色块, 在色板中选中绿色, 那么目录文件将显示为绿色。

假如出现了例外,运行 dircolors -p 显示 DIR 01;35 # directory 那么目录的ASNI颜色是35 , 则想要修改目录的显示颜色,则需要点 第一行第六个色块

到这里终于可以明明白白的修改颜色显示了。


下面是一个脚本文件,打印显示所有已定义的颜色规则

  1. #!/bin/bash
  2. # For LS_COLORS, print type and description in the relevant color.
  3. IFS=:
  4. for ls_color in $LS_COLORS; do
  5. color="${ls_color#*=}"
  6. type="${ls_color%=*}"
  7. # Add descriptions for named types.
  8. case "$type" in
  9. bd) type+=" (block device)" ;;
  10. ca) type+=" (file with capability)" ;;
  11. cd) type+=" (character device)" ;;
  12. di) type+=" (directory)" ;;
  13. do) type+=" (door)" ;;
  14. ex) type+=" (executable file)" ;;
  15. fi) type+=" (regular file)" ;;
  16. ln) type+=" (symbolic link)" ;;
  17. mh) type+=" (multi-hardlink)" ;;
  18. mi) type+=" (missing file)" ;;
  19. no) type+=" (normal non-filename text)" ;;
  20. or) type+=" (orphan symlink)" ;;
  21. ow) type+=" (other-writable directory)" ;;
  22. pi) type+=" (named pipe, AKA FIFO)" ;;
  23. rs) type+=" (reset to no color)" ;;
  24. sg) type+=" (set-group-ID)" ;;
  25. so) type+=" (socket)" ;;
  26. st) type+=" (sticky directory)" ;;
  27. su) type+=" (set-user-ID)" ;;
  28. tw) type+=" (sticky and other-writable directory)" ;;
  29. esac
  30. # Separate each color with a newline.
  31. if [[ $color_prev ]] && [[ $color != $color_prev ]]; then
  32. echo
  33. fi
  34. printf "\e[%sm%s\e[m " "$color" "$type"
  35. # For next loop
  36. color_prev="$color"
  37. done
  38. echo

运行这个脚本,可以看到不同类型的文件的显示效果不同。
运行效果

参考链接 http://www.cnblogs.com/xlmeng1988/archive/2013/01/08/shell_color.html
http://blog.chinaunix.net/uid-26021340-id-3481924.html
https://askubuntu.com/questions/17299/what-do-the-different-colors-mean-in-ls

版权声明:本文为tan00原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/tan00/p/10007848.html