Skip to content

[Linux] 如何更改 Terminal (終端機) 中的檔案顏色

最近一直在研究如何調整自己 Linux 作業系統底下的視覺效果,也拜此所賜,今天便來紀錄如何在 “Terminal” (終端機) 中進行資料夾顏色的調整。

若是想要在圖形化界面當中調整資料夾顏色,可以參考我之前寫過的《使用 folder-color 將 Nautilus 資料夾更換顏色》這篇文章。

而在 Terminal 當中,預設的資料夾多半長這樣:

而在 Terminal 之中,我們是可以修改這個資料夾顏色的。


使用 dircolors 指令修改顏色

在 Linux 作業系統底下,我們可以使用 “dircolors” 指令查看當前設置。加上 -p 參數更能將設定輸出為我們可以修改的文件:

dircolors -p > .dircolors 
vim .dircolors

然後,在 .dircolors 當中找到

DIR 01;34

這個參數設定;在 VIM 中可以使用 “Esc”、然後輸入 “/DIR” 去匹配。

這裡的 01 為 Bold (粗體)、34 為 Blue。設定之間需要以 “;” 作為間隔。

可以設定的參數如下:

 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

詳細的說明可以參照:https://linux.die.net/man/5/dir_colors


效果

最後來展示一下效果:

比如說我選擇了:https://linux.die.net/man/5/dir_colors

DIR 33;01;03;04

按照上方的說明,33 為黃棕色、01 基本上為粗體、03 為斜體 (上方說明有所闕漏)、04 為底線 —— 所以我的資料夾顯示方式會非常特別。

存檔離開,使用:

bash

指令重新設定 Terminal,可以看到我的 Terminal 資料夾顯示為:

非常古怪!我已經想要換掉了。

Tags:

Leave a Reply取消回覆

Click to Copy
Exit mobile version