簡體   English   中英

我在Ubuntu 18.04中遇到命令行顏色問題,如何解決此問題?

[英]I am having problems with my command line colors in Ubuntu 18.04 how can I fix this?

最近,我在VMware中使用Ubuntu 18.04,但命令行存在一些問題。 我特別喜歡Ubuntu的顏色設計,因為顏色一詞幫助我區分文件的類型。(綠色是我最喜歡的,它非常漂亮。)但是,當我今天打開它時,命令行僅顯示白色文本,這非常令人沮喪。 我試圖重設設置,但不知道如何。 如何重置整體終端樣式? 我使用了基本設置,但沒有用。 在此處輸入圖片說明 有什么問題,我該如何解決? (上面的圖片是默認狀態圖片,是我遇到的問題)

此答案歸功於@ rubo77原始答案: https ://askubuntu.com/a/466203/460493

要更改目錄顏色,請使用編輯器打開~/.bashrc文件。

nano ~/.bashrc

並在文件末尾輸入以下內容:

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

一些不錯的顏色選擇(在本例中為0;35為紫色)是:

Blue = 34
Green = 32
Light Green = 1;32
Cyan = 36
Red = 31
Purple = 35
Brown = 33
Yellow = 1;33
Bold White = 1;37
Light Grey = 0;37
Black = 30
Dark Grey= 1;30

第一個數字是樣式(1 =粗體),然后是分號,然后是顏色的實際數字,可能的樣式(效果)是:

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)

可能的背景:

40  = black background
41  = red background
42  = green background
43  = orange background
44  = blue background
45  = purple background
46  = cyan background
47  = grey background
100 = dark grey background
101 = light red background
102 = light green background
103 = yellow background
104 = light blue background
105 = light purple background
106 = turquoise background
107 = white background

所有可能的顏色:

31  = red
32  = green
33  = orange
34  = blue
35  = purple
36  = cyan
37  = grey
90  = dark grey
91  = light red
92  = light green
93  = yellow
94  = light blue
95  = light purple
96  = turquoise
97  = white

甚至可以將它們組合起來,這樣一個參數就可以了:

di=1;4;31;42

在您的LS_COLORS變量中將使目錄以加粗下划線的紅色文本顯示,並帶有綠色背景!

要在終端中測試所有這些顏色和樣式,可以使用以下之一:

for i in 00{2..8} {0{3,4,9},10}{0..7}
do echo -e "$i \e[0;${i}mSubdermatoglyphic text\e[00m  \e[1;${i}mSubdermatoglyphic text\e[00m"
done

for i in 00{2..8} {0{3,4,9},10}{0..7}
do for j in 0 1
   do echo -e "$j;$i \e[$j;${i}mSubdermatoglyphic text\e[00m"
   done
done

您還可以在使用ls命令時更改其他類型的文件,方法是通過定義每種類型:

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

Bigsoft-配置LS_COLORS上提供了更完整的列表。

在某些發行版上,您可能還想將ow "(OTHER_WRITABLE) whose default is non-readable"的背景顏色更改為綠色背景上的非粗體藍色文本。

例如,您可以在.bashrc文件的末尾使用LS_COLORS="$LS_COLORS:di=1;33" ,以在黑色背景上獲得漂亮的可讀加粗橙色文本。

更改.bashrc文件后, .bashrc更改生效,您將必須重新啟動Shell或運行源~/.bashrc

注意:例如,您可以將更多命令與冒號結合使用

LS_COLORS=$LS_COLORS:'di=1;33:ln=36' ; export LS_COLORS; ls

資源:

[COLORS Lscolors - Linux StepByStep][2]
[Geek Gumbo - Changing the Directory Color in Bash][2]

假設您使用bash作為外殼,通常在.bash_profile.bashrc文件中進行設置。 看起來您在這些圖像中位於兩台不同的計算機上。 您可以在兩者之間進行復制,這可能會有所幫助。 例如:

scp gayan@V131:/home/gayan/.bash_profile ~/.bash_profile
source ~/.bash_profile

如果沒有幫助,則您的終端應用程序可能未配置顏色。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM