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.www58058.com/52731

(0)
陸 東貴陸 東貴
上一篇 2016-10-18
下一篇 2016-10-18

相關推薦

  • 苦上半年時間

    這是一種享受

    Linux干貨 2016-08-08
  • Linux系統程序包管理之RPM

    rpm包概述 RPM 是 Red at Package Manager 的縮寫,本意是Red Hat 軟件包管理,顧名思義是Red Hat 貢獻出來的軟件包管理工具;在Fedora 、Redhat、Mandriva、SuSE、YellowDog等主流發行版本,以及在這些版本基礎上二次開發出來的發行版采用。 RPM包里面都包含什么?里面包含可執行的二進制程序,…

    Linux干貨 2016-08-24
  • N25第一周作業

    1.描述計算機的組成及其功能   計算機整體上分為兩大部分:     一、硬件部分:運算器,存儲器,控制器,輸入設備,輸出設備     運算器是對數據進行加工處理,主要是指各種算術運算與邏輯運算     存儲器是存儲各種數據、信號、命令等信息并在他們需要時提供這些信息 &nbsp…

    Linux干貨 2016-12-03
  • M20-1 8月3號 ACL訪問控制列表

    一、acl簡介:   access control list,用于實現靈活的權限管理,除了文件的所有者,所屬組和其他人,可以對更多的用戶設置權限,而acl生效的順序是所有者,自定義用戶組,自定義組,其他人。 二、ACL的設置技巧:   getfacl:取得某個文件/目錄的ACL設置項目   setfacl:設置某個目錄/文件的A…

    Linux干貨 2016-08-08
  • Linux Sysadmin–part2

    1、寫一個腳本,使用ping命令探測192.168.4.1-192.168.4.254之間的所有主機的在線狀態; 在線的主機使用綠色顯示; 不在線的主使用紅色顯示; #!/bin/bash #description: #date: #Author: for i in {1..254}; do if ping -c 3 192.168.4.$i &&g…

    2017-09-19
  • linux下find(文件查找)命令的詳解

    文件查找命令locate和find詳解 locate 配合數據庫緩存,快速查看文件位置,非實時查找( 數據庫查找) find 實際搜尋硬盤查詢文件名稱 ,實時查找 locate簡介 locate命令其實是find -name的另一種寫法,但是要比后者快得多,原因在于它不搜索具體目錄,而是搜索一個數據庫/var/lib/locat…

    Linux干貨 2016-08-18
欧美性久久久久