1. 程式人生 > >Ubuntu下使用ls命令顯示檔案顏色相關內容及修改

Ubuntu下使用ls命令顯示檔案顏色相關內容及修改

<轉載自:http://pcyoyo.com/?p=465>

在Ubuntu下,使用ls命令顯示目錄下檔案及資料夾時會先顯示不同顏色,如下圖所示:


如果知道了不同顏色分別代表的含義,那麼對於我們檢視目錄下檔案資訊方便了很多,所以就搜尋了一下相關文章,找到一篇,如下所示:

# Attribute codes: 字元屬性
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
#00無 01粗體 04下劃線 05閃爍 07反轉 08隱藏
# Text color codes: 字元顏色
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
#30黑 31紅 32綠 33黃 34藍 35粉紅 36淡藍 37白
# Background color codes: 字元背景色
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
#40黑 41紅 42綠 43黃 44藍 45粉紅 46淡藍 47白
NORMAL 00 # global default, although everything should be something. 普通檔案 終端預設顏色
FILE 00 # normal file 普通檔案 終端預設顏色
DIR 01;34 # directory 目錄 粗體-藍字
LINK 01;36 # symbolic link. (If you set this to ‘target’ instead of a 符號連結 粗體-淡藍字
# numerical value, the color is as for the file pointed to.)
FIFO 40;33 # pipe 管道API 黑底-黃字
SOCK 01;35 # socket 套接字API 粗體-粉紅字
DOOR 01;35 # door 門API 粗體-粉紅字
BLK 40;33;01 # block device driver 塊裝置驅動 粗體-黑底-黃字
CHR 40;33;01 # character device driver 字元裝置驅動 粗體-黑底-黃字
ORPHAN 40;31;01 # symlink to nonexistent file 指向檔案不存在的符號連結 粗體-黑底-紅字
SETUID 37;41 # file that is setuid (u+s) 指定UID的檔案 紅底-白字
SETGID 30;43 # file that is setgid (g+s) 指定GID的檔案 黃底-黑字
STICKY_OTHER_WRITABLE 30;42 # dir that is sticky and other-writable (+t,o+w) +t,o+w許可權的檔案 綠底-黑字(不常用)
OTHER_WRITABLE 34;42 # dir that is other-writable (o+w) and not sticky -t,o+w許可權的檔案 綠底-藍字(不常用)
STICKY 37;44 # dir with the sticky bit set (+t) and not other-writable +t,o-w許可權的檔案 藍底-白字(不常用)
# This is for files with execute permission:
EXEC 01;32 有執行許可權的檔案 粗體-綠字
# List any file extensions like ‘.gz’ or ‘.tar’ that you would like ls
# to colorize below. Put the extension, a space, and the color init string.
# (and any comments you want to add after a ‘#’)
# If you use DOS-style suffixes, you may want to uncomment the following:
#.cmd 01;32 # executables (bright green) .cmd可執行檔案 粗體-綠字(亮)
#.exe 01;32 .exe檔案 粗體-綠字
#.com 01;32 .com檔案 粗體-綠字
#.btm 01;32 .btm檔案 粗體-綠字
#.bat 01;32 .bat檔案 粗體-綠字
.tar 01;31 # archives or compressed (bright red) .tar壓縮檔案 粗體-紅字(亮)
.tgz 01;31 .tgz檔案 粗體-紅字
.arj 01;31 .arj檔案 粗體-紅字
.taz 01;31 .taz檔案 粗體-紅字
.lzh 01;31 .lzh檔案 粗體-紅字
.zip 01;31 .zip檔案 粗體-紅字
.z 01;31 .z檔案 粗體-紅字
.Z 01;31 .Z檔案 粗體-紅字
.gz 01;31 .gz檔案 粗體-紅字
.bz2 01;31 .bz2檔案 粗體-紅字
.deb 01;31 .deb檔案 粗體-紅字
.rpm 01;31 .rpm檔案 粗體-紅字
.jar 01;31 .jar檔案 粗體-紅字
# image formats
.jpg 01;35 .jpg圖片 粗體-粉紅字
.jpeg 01;35 .jpeg圖片 粗體-粉紅字
.gif 01;35 .gif圖片 粗體-粉紅字
.bmp 01;35 .bmp圖片 粗體-粉紅字
.pbm 01;35 .pbm 圖片 粗體-粉紅字
.pgm 01;35 .pgm圖片 粗體-粉紅字
.ppm 01;35 .ppm圖片 粗體-粉紅字
.tga 01;35 .tga圖片 粗體-粉紅字
.xbm 01;35 .xbm圖片 粗體-粉紅字
.xpm 01;35 .xpm圖片 粗體-粉紅字
.tif 01;35 .tif圖片 粗體-粉紅字
.tiff 01;35 .tiff圖片 粗體-粉紅字
.png 01;35 .png 圖片 粗體-粉紅字
.mov 01;35 .mov視訊 粗體-粉紅字
.mpg 01;35 .mpg視訊 粗體-粉紅字
.mpeg 01;35 .mpeg視訊 粗體-粉紅字
.avi 01;35 .avi視訊 粗體-粉紅字
.fli 01;35 .fli視訊 粗體-粉紅字
.gl 01;35 .gl視訊 粗體-粉紅字
.dl 01;35 .dl視訊 粗體-粉紅字
.xcf 01;35 .xcf視訊 粗體-粉紅字
.xwd 01;35 .xwd視訊 粗體-粉紅字
# audio formats
.flac 01;35 .flac音訊 粗體-粉紅字
.mp3 01;35 .mp3音訊 粗體-粉紅字
.mpc 01;35 .mpc音訊 粗體-粉紅字
.ogg 01;35 .ogg音訊 粗體-粉紅字
.wav 01;35 .wav音訊 粗體-粉紅字

PS: 檔案可執行許可權的顏色顯示優先於檔案可讀寫許可權

顏色著實不少,可以記幾個常用的,儲存起來留著以後查閱使用。

其實呢,使用dircolor命令就可以顯示檔名顏色設定了(dircolor -p)(它還可以設定)。

關於如何修改,同樣找到下面一篇文章:

1. 利用dircolors命令,檢視我們的系統當前的檔名稱顯示顏色的值,然後利用管道重定向到使用者目錄下的任意一個檔案(這裡我們建立了一個.dir_colors檔案)

命令1: cd ~

命令2: dircolors -p > .dir_colors

2. 用vim開啟.dir_colors檔案,然後找到“DIR 01;34” //這裡的01表示高亮度顯示,34表示藍色,33表示黃色

修改為 “DIR 01;33”,儲存退出

3. 為了將修改之後的配置檔案匯入到dircolors中,我們採取如下的方案

開啟使用者目錄下的.bashrc檔案,找到類似“eval ‘dircolors -b ‘”(如果沒有自行新增),

修改為 eval ‘dircolors -b .dir_colors’ 儲存退出 //這裡的.dir_colors就是我們前面自己建立的檔案

4. 為了讓修改生效,退出,並重新進入系統

命令: exit

5. 就可以按照你的意思來顯示目錄了

有關檔案顏色顯示的相關檔案說明,及執行順序什麼的,下次再詳細介紹吧!

參考連結:

http://forum.ubuntu.org.cn/viewtopic.php?t=113593

http://hi.baidu.com/windhl/blog/item/e2d4b60f5e0ce6e1aa64571a.html