Linux文件類型及顏色標識整理linux
使用工具:shell
ls命令app
ls –l:以常格式顯示文件及目錄的詳細信息less
例如:-rw-r--r-- 1 root root 0 10月 12 13:32 2016-10-12-13-32-11socket
-rw-------.1 root root 1487 9月 12 10:56 anaconda-ks.cfgide
drwxr-xr-x 3 root root 51 10月 14 10:18 application工具
根據示例顯示,各類文件的文件名是以不一樣顏色顯示來區分字體
文件類型介紹:ui
-:常規文件,普通文件;this
d:目錄文件,路徑映射;
b:塊設備文件;支持以「block」爲單位進行隨機訪問;
c:字符設備文件,支持以「character」爲單位進行線性訪問;
mojornumber:主設備號,表示設備類型,進而肯定要加載的驅動;
minornumber:次設備號,標識同一類型中的不一樣設備;
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 / UnixCommand: dir_colors
NAMEdir_colors - configuration file for
dircolors
(1)
DESCRIPTIONThe program
ls
(1) uses the environment variable LS_COLORS to determine the colorsin which the filenames are to be displayed. This environment variable isusually set by a command like
eval `dircolors some_path/dir_colors`
found in a system default shell initialization file, like /etc/profileor /etc/csh.cshrc. (See also
dircolors
(1).) Usually, the file used here is /etc/DIR_COLORS and can beoverridden by a .dir_colors file in one's home directory.
This configuration file consists of several statements, one per line. Anythingright of a hash mark (#) is treated as a comment, if the hash mark is at thebeginning of a line or is preceded by at least one whitespace. Blank lines areignored.
The global section of the file consists of any statement before thefirst TERM statement. Any statement in the global section of the file isconsidered valid for all terminal types. Following the global section is one ormore terminal-specific sections, preceded by one or more TERMstatements which specify the terminal types (as given by the TERMenvironment variable) the following declarations apply to. It is alwayspossible to override a global declaration by a subsequent terminal-specificone.
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 appliesfor 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 aterminal (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 bydefault. For compatibility reasons, this can also be specified as 1 for yesor 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. Theoptions can be any valid ls command line options, and should include theleading minus sign. Please note that dircolors does not verify thevalidity 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 anonexistent file). If this is unspecified, ls will use the LINKcolor instead.
MISSING color-sequence
Specifies the color used for a missing file (a nonexistent file whichnevertheless has a symbolic link pointing to it). If this is unspecified, lswill 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 (Solaris2.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 thatends 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 consideredobsolete.
ISO 6429 (ANSI) COLOR SEQUENCESMost color-capable ASCII terminals today use ISO6429 (ANSI) color sequences, and many common terminals without colorcapability, including xterm and the widely used and cloned DEC VT100,will recognize ISO 6429 color codes and harmlessly eliminate them from theoutput or emulate them. ls uses ISO 6429 codes by default, assumingcolorization is enabled.
ISO 6429 color sequences are composed of sequences of numbers separated bysemicolons. 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 Orphannedsymbolic 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 getscolorized after you do a directory listing, change the NORMAL and FILEcodes to the numerical codes for your normal foreground and backgroundcolors.
OTHER TERMINAL TYPES (ADVANCED CONFIGURATION)If you have a color-capable (orotherwise highlighting) terminal (or printer!) which uses a different set ofcodes, you can still generate a suitable setup. To do so, you will have to usethe 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 orname of file. If the ENDCODE is undefined, the sequence LEFTCODENORMAL RIGHTCODE will be used instead. The purpose of the left- andrightcodes is merely to reduce the amount of typing necessary (and to hide uglyescape codes away from the user). If they are not appropriate for yourterminal, you can eliminate them by specifying the respective keyword on a lineby itself.
NOTE: If the ENDCODE is defined in the global section of thesetup file, it cannot be undefined in a terminal-specific section of thefile. This means any NORMAL definition will have no effect. A different ENDCODEcan, however, be specified, which would have the same effect.
ESCAPE SEQUENCESTo specify control- or blank characters in the color sequencesor 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, orany control character anywhere in the string, as well as a hash mark as thefirst character.