Linux文件类型及颜色标识整理

Linux文件类型及颜色标识整理

M21陆东贵

使用工具:

ls命令

    ls –l:以常格式显示文件及目录的详细信息

    例如:-rw-r–r–  1 root root       0 10月 12 13:32 2016-10-12-13-32-11

-rw——-. 1 root root    1487 9月  12 10:56 anaconda-ks.cfg

drwxr-xr-x  3 root root      51 10月 14 10:18 application

根据示例显示,各种文件的文件名是以不同颜色显示来区分

文件类型介绍:

    –:常规文件,普通文件;

    d:目录文件,路径映射;

    b:块设备文件;支持以“block”为单位进行随机访问;

    c:字符设备文件,支持以“character”为单位进行线性访问;

       mojor number:主设备号,表示设备类型,进而确定要加载的驱动;

       minor number:次设备号,标识同一类型中的不同设备;

    l:符号链接文件;

    p:命令管道文件;

    s:socket 套接字文件;

文件颜色介绍:

蓝色:目录

绿色:可执行文件

红色:压缩文件

浅蓝色:链接文件

白色:其他文件

黄色:设备文件,包括block, char, fifo。

红色闪烁:链接的文件有问题了;

拓展:

1可以使用dircolors -p看到缺省的颜色设置,包括各种颜色和“粗体”,下划线,闪烁等定义。

2在/etc/DIR_COLORS文件,这是一个着色控制的模版。

3修改其他颜色的方法:

首先

# vi /etc/DIR_COLORS

内的设定“DIR 01;34”,为ls命令的目录的颜色设置,01表示粗体,34表示字体蓝色。

我把它改成了“DIR 01;37;44”,37是字体白色,44是字背景蓝色,视觉效果还可以,而且习惯上也能接受。

然后,执行

# eval `dircolors /etc/DIR_COLORS`

4以上方法是对全局修改,个人用户修改方法:

将/etc/DIR_COLORS文件cp到~/下,并改名为.dir_colors,再修改这个文件就可以了

 

以下是官方文档说明:

Linux / Unix Command: dir_colors

NAMEdir_colors – configuration file for
dircolors
(1)   
DESCRIPTIONThe program
ls
(1) uses the environment variable LS_COLORS to determine the colors in which the filenames are to be displayed. This environment variable is usually set by a command like
eval `dircolors some_path/dir_colors`
found in a system default shell initialization file, like /etc/profile or /etc/csh.cshrc. (See also
dircolors
(1).) Usually, the file used here is /etc/DIR_COLORS and can be overridden by a .dir_colors file in one's home directory.
This configuration file consists of several statements, one per line. Anything right of a hash mark (#) is treated as a comment, if the hash mark is at the beginning of a line or is preceded by at least one whitespace. Blank lines are ignored.
The global section of the file consists of any statement before the first TERM statement. Any statement in the global section of the file is considered valid for all terminal types. Following the global section is one or more terminal-specific sections, preceded by one or more TERM statements which specify the terminal types (as given by the TERM environment variable) the following declarations apply to. It is always possible to override a global declaration by a subsequent terminal-specific one.
The following statements are recognized; case is insignificant:
TERM terminal-type
Starts a terminal-specific section and specifies which terminal it applies to. Multiple TERM statements can be used to create a section which applies for several terminal types.
COLOR yes|all|no|none|tty
(Slackware only; ignored by GNU
dircolors
(1).) Specifies that colorization should always be enabled (yes or all), never enabled (no or none), or enabled only if the output is a terminal (tty). The default is no.
EIGHTBIT yes|no
(Slackware only; ignored by GNU
dircolors
(1).) Specifies that eight-bit ISO 8859 characters should be enabled by default. For compatibility reasons, this can also be specified as 1 for yes or 0 for no. The default is no.
OPTIONS options
(Slackware only; ignored by GNU
dircolors
(1).) Adds command line options to the default ls command line. The options can be any valid ls command line options, and should include the leading minus sign. Please note that dircolors does not verify the validity of these options.
NORMAL color-sequence
Specifies the color used for normal (non-filename) text.
FILE color-sequence
Specifies the color used for a regular file.
DIR color-sequence
Specifies the color used for directories.
LINK color-sequence
Specifies the color used for a symbolic link.
ORPHAN color-sequence
Specifies the color used for an orphaned symbolic link (one which points to a nonexistent file). If this is unspecified, ls will use the LINK color instead.
MISSING color-sequence
Specifies the color used for a missing file (a nonexistent file which nevertheless has a symbolic link pointing to it). If this is unspecified, ls will use the FILE color instead.
FIFO color-sequence
Specifies the color used for a FIFO (named pipe).
SOCK color-sequence
Specifies the color used for a socket.
DOOR color-sequence
(Supported since file-utils 4.1) Specifies the color used for a door (Solaris 2.5 and later).
BLK color-sequence
Specifies the color used for a block device special file.
CHR color-sequence
Specifies the color used for a character device special file.
EXEC color-sequence
Specifies the color used for a file with the executable attribute set.
LEFTCODE color-sequence
Specifies the left code for non-ISO 6429 terminals (see below).
RIGHTCODE color-sequence
Specifies the right code for non-ISO 6429 terminals (see below).
ENDCODE color-sequence
Specifies the end code for non-ISO 6429 terminals (see below).
*extension color-sequence
Specifies the color used for any file that ends in extension.
.extension color-sequence
Same as *.extension. Specifies the color used for any file that ends in .extension. Note that the period is included in the extension, which makes it impossible to specify an extension not starting with a period, such as ~ for emacs backup files. This form should be considered obsolete.   
ISO 6429 (ANSI) COLOR SEQUENCESMost color-capable ASCII terminals today use ISO 6429 (ANSI) color sequences, and many common terminals without color capability, including xterm and the widely used and cloned DEC VT100, will recognize ISO 6429 color codes and harmlessly eliminate them from the output or emulate them. ls uses ISO 6429 codes by default, assuming colorization is enabled.
ISO 6429 color sequences are composed of sequences of numbers separated by semicolons. The most common codes are:
0     to restore default color
1     for brighter colors
4     for underlined text
5     for flashing text
30     for black foreground
31     for red foreground
32     for green foreground
33     for yellow (or brown) foreground
34     for blue foreground
35     for purple foreground
36     for cyan foreground
37     for white (or gray) foreground
40     for black background
41     for red background
42     for green background
43     for yellow (or brown) background
44     for blue background
45     for purple background
46     for cyan background
47     for white (or gray) background
Not all commands will work on all systems or display devices.
ls uses the following defaults:
NORMAL   0       Normal (non-filename) text
FILE     0       Regular file
DIR      32      Directory
LINK     36      Symbolic link
ORPHAN   undefined       Orphanned symbolic link
MISSING  undefined       Missing file
FIFO     31      Named pipe (FIFO)
SOCK     33      Socket
BLK      44;37   Block device
CHR      44;37   Character device
EXEC     35      Executable file
A few terminal programs do not recognize the default properly. If all text gets colorized after you do a directory listing, change the NORMAL and FILE codes to the numerical codes for your normal foreground and background colors.   
OTHER TERMINAL TYPES (ADVANCED CONFIGURATION)If you have a color-capable (or otherwise highlighting) terminal (or printer!) which uses a different set of codes, you can still generate a suitable setup. To do so, you will have to use the LEFTCODE, RIGHTCODE, and ENDCODE definitions.
When writing out a filename, ls generates the following output sequence: LEFTCODE typecode RIGHTCODE filename ENDCODE, where the typecode is the color sequence that depends on the type or name of file. If the ENDCODE is undefined, the sequence LEFTCODE NORMAL RIGHTCODE will be used instead. The purpose of the left- and rightcodes is merely to reduce the amount of typing necessary (and to hide ugly escape codes away from the user). If they are not appropriate for your terminal, you can eliminate them by specifying the respective keyword on a line by itself.
NOTE: If the ENDCODE is defined in the global section of the setup file, it cannot be undefined in a terminal-specific section of the file. This means any NORMAL definition will have no effect. A different ENDCODE can, however, be specified, which would have the same effect.   
ESCAPE SEQUENCESTo specify control- or blank characters in the color sequences or filename extensions, either C-style \-escaped notation or stty-style ^-notation can be used. The C-style notation includes the following characters:
\a      Bell (ASCII 7)
\b      Backspace (ASCII 8)
\e      Escape (ASCII 27)
\f      Form feed (ASCII 12)
\n      Newline (ASCII 10)
\r      Carriage Return (ASCII 13)
\t      Tab (ASCII 9)
\v      Vertical Tab (ASCII 11)
\?      Delete (ASCII 127)
\nnn Any character (octal notation)
\xnnn        Any character (hexadecimal notation)
\_      Space
\\     Backslash (\)
\^      Caret (^)
\#      Hash mark (#)
Please note that escapes are necessary to enter a space, backslash, caret, or any control character anywhere in the string, as well as a hash mark as the first character.   

 

原创文章,作者:陆 东贵,如若转载,请注明出处:http://www.178linux.com/52731

(0)
上一篇 2016-10-18 18:03
下一篇 2016-10-18 18:46

相关推荐

  • 使用pyenv管理不同版本的python

    安装: 安装: $ curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash 在你的shellrc文件中添加: export PATH=”$HOME/.pyenv/bin:$PATH” eval “$(pyenv init …

    Linux干货 2015-03-12
  • 硬链接和软链接的区别

    硬链接和软链接在文件系统实现上的区别决定了两者之间功能上的不同,也就是说硬链接和软链在文件系统上两者实现的方式不同,让其各自具有不同的功能和特色,也决定了各自的优点和缺点。接下同文件系统上创建硬链接和软链接看各自的特点。 一文件系统上创建硬链接 下面命令是在文件系统上创建一个硬链接: ~]# ln test /testdir/t…

    Linux干货 2016-10-29
  • 位置变量$1,$2,$@,$*,$#详解

    位置变量: 位置变量实际是属于系统预定义变量的一种,不能修改变量名,同时作用也是固定的,也不能新增的变量,只能修改变量的值。     常用的位置参数变量        $0代表命令本身,$1-$9代表第一到第九个参数,十以上的参数需要用大括号括起来,比如${11}.     该变…

    Linux干货 2016-08-18
  • hadoop安全模式

    hadoop安全模式在分布式文件系统启动的时候,开始的时候会有安全模式,当分布式文件系统处于安全模式的情况下,文件系统中的内容不允许修改也不允许删除,直到安全模式结束。安全模式主要是为了系统启动的时候检查各个DataNode上数据块的有效性,同时根据策略必要的复制或者删除部分数据块。运行期通过命令也可以进入安全模式。在实践过程中,系统启动的时候去修改和删除文…

    Linux干货 2015-04-13
  • Python函数式编程指南(二):函数

    这是此系列的第二篇,试图说明在Python中如何更好地使用函数并引导诸位使用函数式的思维进行思考。掌握并应用这些内容,就已经是至少形似的函数式风格的代码了,至于思维么,这个真靠自己。 作者水平有限,如有错漏之处还请指出;转载请注明原作者和原地址:) 2. 从函数开始 2.1. 定义一个函数 如下定义了一个求和函数: def add(x, y): return…

    Linux干货 2015-03-11
  • 20160804课堂练习

    grep正则表达式课堂练习 1、找出ifconfig命令结果中本机的所有IPv4地址 # ifconfig | head -2 | cut -dt -f2 | cut -dn -f1 | tail -1 2、  查出分区空间使用率的最大百分比值 # df | cut -c56-58 | sort -n | tail -1 3、  查出用户…

    Linux干货 2016-08-05