讓 FreeBSD 的終端機也多彩多姿另一章

頭城國小資訊組 | 讓 FreeBSD 的終端機也多彩多姿 中雖然設定讓終端機有顏色,可是目錄顏色比較暗,甚至看不太清楚。

在網路上搜尋了一下,找到這些可以參考的文章:
FreeBSD: Enable Colorized ls Output
How To Enable ls Color?
color ls in FreeBSD (in the Bash shell) | Jared Evans Global Microbrand
ls 顏色設定(in Bash shell) – Tsung’s Blog[@more@]設定的方式:
以 bash shell 為例
/etc/profile 加入下面一行
# vim /etc/profile
export LSCOLORS=”gxfxcxdxcxegedabagacad”
alias ls=’ls -GF’

讓設定生效
# source /etc/profile
更改之後

其中 LSCOLORS 參數的設定一直都沒看懂,後來在 Mac 讓終端機 ls 有顏色 « Soda Hau’s Note 上才看懂了!

LSCOLORS 後面一串的意思是,照著順序設定顏色(共 11 項),順序是:
    directory
    symbolic link
    socket
    pipe
    executable
    block special
    character special
    executable with setuid bit set
    executable with setgid bit set
    directory writable to others, with sticky bit
    directory writable to others, without sticky bit

顏色的對應值則是:
    a -> black
    b -> red
    c -> green
    d -> brown
    e -> blue
    f -> magenta
    g -> cyan
    h -> light grey

    A -> bold black, usually shows up as dark grey
    B -> bold red
    C -> bold green
    D -> bold brown, usually shows up as yellow
    E -> bold blue
    F -> bold magenta
    G -> bold cyan
    H -> bold light grey; looks like bright white
    x -> default foreground or background

每個種類的檔案有兩個值,字的顏色和底色。以 LSCOLORS=”gxfxcxdxcxegedabagacad” 來說,
前面的 gx 是設定資料夾顯示的顏色為青色,底色是預設的前景和背景色;
            fx 是 symbolic link 的設定,字是洋紅色,底色是預設的前景和背景色
            cx 是 socket 的設定,字是 green 色,底色是預設的前景和背景色
            dx 是 pipe 的設定,字是 brown 色,底色是預設的前景和背景色
            cx 是 executable 的設定,字是 green 色,底色是預設的前景和背景色
            eg 是 block special 的設定,字是 blue 色,底色是 cyan 色
            ed 是 character special  的設定,字是 blue 色,底色是 brown 色
            ab 是 executable with setuid bit set 的設定,字是 black 色,底色是 red 色
            ag 是 executable with setgid bit set 的設定,字是 black 色,底色是 cyan 色
            ac 是 directory writable to others, with sticky bit 的設定,字是 black 色,底色是 green 色
            ad 是 directory writable to others, without sticky bit 的設定,字是 black色,底色是 brown 色

另外也可以直接由 LSCOLORS Generator 網站上設定,會比較簡單方便!