【问题标题】:I am having problems with my command line colors in Ubuntu 18.04 how can I fix this?我在 Ubuntu 18.04 中的命令行颜色有问题,我该如何解决?
【发布时间】:2018-09-26 16:00:53
【问题描述】:

最近我在 VMware 中使用 Ubuntu 18.04,但我遇到了一些命令行问题。我特别喜欢 Ubuntu 的颜色设计,因为颜色这个词帮助我区分文件的类型。(我最喜欢的是绿色,非常漂亮)但是今天打开它时,命令行只显示白色文本,非常令人沮丧。我试图重置设置,但我不知道如何。如何重置整体终端风格?我使用了基本设置,但没有用。这是什么问题,我该如何解决? (上图是默认状态图下是我遇到的问题)

【问题讨论】:

    标签: ubuntu terminal command


    【解决方案1】:

    这个答案的功劳归于@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=bold),后面是分号,然后是颜色的实际数字,可能的样式(效果)有:

    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 - Configuring LS_COLORS 提供更完整的列表。

    在某些发行版中,您可能还希望将 ow "(OTHER_WRITABLE) whose default is non-readable" 的背景颜色更改为绿色背景上的非粗体蓝色文本。

    例如,您可以在 .bashrc 文件的末尾使用 LS_COLORS="$LS_COLORS:di=1;33",以在黑色背景上获得清晰易读的粗体橙色文本。

    修改.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]
    

    【讨论】:

    • 您是否重新获取了.bashrc 文件?进行更改后运行source ~/.bashrc 或关闭终端并重新打开一个。
    【解决方案2】:

    假设您使用 bash 作为 shell,这通常在您的 .bash_profile.bashrc 文件中设置。在这些图像中,您似乎在两台不同的机器上。您可以在两者之间进行复制,这可能会有所帮助。例如:

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

    如果没有帮助,那么您的终端应用程序可能没有配置颜色。

    【讨论】:

    • 不,它不是两台不同的机器。上图是我在网上拍的。我只有一台机器在
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-05
    • 2021-04-02
    • 2020-03-25
    • 2020-02-14
    相关资源
    最近更新 更多