[精讚] [會員登入]
339

[Linux] 怎麼修改終端機console下ls的顏色?

在linux下的ls使用--color的參數時,雖然目錄有上色,但是顏色是深藍色很難辨識,要怎麼修改呢?

分享此文連結 //n.sfs.tw/16427

分享連結 [Linux] 怎麼修改終端機console下ls的顏色?@新精讚
(文章歡迎轉載,務必尊重版權註明連結來源)
2024-06-12 21:30:44 最後編修
2024-06-12 21:29:04 By 張○○
 

自動目錄

在linux下的ls使用--color的參數時,雖然目錄有上色,但是顏色是深藍色很難辨識,加上老花加重,實在看不清楚,要怎麼修改呢?

這篇主要是參考[1]裡的說明,非常的詳細,節錄一部分符合我的需要。

一、修改  ~/.bashrc

最後面加入以下內容

LS_COLORS=$LS_COLORS:'di=0;94:'; export LS_COLORS;

修改完後執行生效

$ source  ~/.bashrc

非常的簡單

 

二、設定方式說明

LS_COLORS 的格式如下:

  類型=格式1;格式2;格式3...:類型=格式1;格式2;格式3...:...

類型可有多種格式,格式間用分號區隔 ';',多個類型用冒號區隔 ':'。

例如

LS_COLORS=$LS_COLORS:'di=0;94:fi=1;4;41;93';

這樣目錄會是減藍色,一般檔案會是粗體黃色加底線,像這樣。

 

三、類型代號

bd = (BLOCK, BLK)   Block device (buffered) special file
cd = (CHAR, CHR)    Character device (unbuffered) special file
di = (DIR)  Directory
do = (DOOR) [Door][1]
ex = (EXEC) Executable file (ie. has 'x' set in permissions)
fi = (FILE) Normal file
ln = (SYMLINK, LINK, LNK)   Symbolic link. If you set this to ‘target’ instead of a numerical value, the color is as for the file pointed to.
mi = (MISSING)  Non-existent file pointed to by a symbolic link (visible when you type ls -l)
no = (NORMAL, NORM) Normal (non-filename) text. Global default, although everything should be something
or = (ORPHAN)   Symbolic link pointing to an orphaned non-existent file
ow = (OTHER_WRITABLE)   Directory that is other-writable (o+w) and not sticky
pi = (FIFO, PIPE)   Named pipe (fifo file)
sg = (SETGID)   File that is setgid (g+s)
so = (SOCK) Socket file
st = (STICKY)   Directory with the sticky bit set (+t) and not other-writable
su = (SETUID)   File that is setuid (u+s)
tw = (STICKY_OTHER_WRITABLE)    Directory that is sticky and other-writable (+t,o+w)
*.extension =   Every file using this extension e.g. *.rpm = files with the ending .rpm

四、格式及顏色代號

0   = default colour
1   = bold
4   = underlined
5   = flashing text (disabled on some terminals)
7   = reverse field (exchange foreground and background color)
8   = concealed (invisible)

顏色代碼 <下面圖是由[1]提供的shell執行結果>

 

最後提供我的設定 ~/.bashrc:

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi

# User specific environment
if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]
then
    PATH="$HOME/.local/bin:$HOME/bin:$PATH"
fi
export PATH

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias ll='ls --color -al'
alias vi='vim'

LS_COLORS=$LS_COLORS:'di=0;94:'; export LS_COLORS;

顏色就這麼多,加減用。

 

 

參考資料

[1] https://askubuntu.com/questions/466198/how-do-i-change-the-color-for-directories-with-ls-in-the-console

END

你可能感興趣的文章

[SELINUX] php 呼叫系統程式(使用exec, system等)執行網路服務 這近想透過PHP呼叫系統的程式來執行網路的服務,怎麼測試都失敗…

[Rocky9] codeignitor4+ php:8.3-apache + docker compose 這次的目標是把服務裝在docker,裡面放入php8.3-apache的 docker container, 並採用codeignitor4作基礎的設置。

SELinux 常用指令和檔案 在Redhat系列中,Centos5以後加入了selinux,他並沒有這麼可怕,不必每次看到Selinux ,就想把他

[Rocky9] Sphinx 3支援中文 + Docker + PHP7 使用docker建置sphinxsearch 3

[postfix] open /etc/postfix/main.cf: Permission denied 等錯誤 遇到開啟 /etc/postfix/main.cf: Permission denied 等錯誤解決

[Centos8] 利用nmcli 設定ipv4 位址 Centos7之後修改網路設定變得比較麻煩一點,此篇介紹使用nmcli指令的方法

我有話要說

>>

限制:留言最高字數1000字。 限制:未登入訪客,每則留言間隔需超過10分鐘,每日最多5則留言。

訪客留言

[無留言]

隨機好文

[jQuery] textarea 的取值和給值 HTML 的 TEXTAREA 標籤若要用 jquery 取值,不能使用 .text() 或 .html() ,使用 .

[bc] linux 的計算機 bc 設定小數位數、計算π、次方根 linux 的計算機 bc 設定小數位數、計算π、次方根

UTF-8的網頁但IE8一片空白 UTF8編碼的網頁在Firefox 正常顯示、但IE8 就是空白,IE8編碼設定是「自動偵測」可是自動偵測到的是 big5...

世紀帝國征服者新版本--被遺忘的帝國 世紀帝國征服者新版本--被遺忘的帝國 世紀二代的征服者是精典遊戲中的精典,aofe更好玩...

Smarty安裝 smarty 是著名的樣版引擎,非常的好用,用多了突然發現拿掉smarty反而不會寫php了,以下是安裝過程..