Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to change the color of Linux command line terminal interface

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to change the color of the Linux command line terminal interface". In the daily operation, I believe that many people have doubts about how to change the color of the Linux command line terminal interface. The editor consulted all kinds of materials and sorted out a simple and useful method of operation. I hope it will be helpful to answer the doubt of "how to change the color of the Linux command line terminal interface". Next, please follow the editor to study!

GNOME Terminal already supports 256 colors, but perhaps for maximum compatibility, it does not set an environment variable to claim to support it. Therefore, only export TERM=xterm-256color is needed to let the command line program know that the terminal supports 256colors. Add it to your .bashrc or .profile and open a new Bash or session to see if your terminal program (such as vim) is a little richer in color.

In addition, if you use tmux (byobu), you can modify your .tmux.conf file (byobu is .byobu / .tmux.conf) to make the screen/tmux session more beautiful:

The code is as follows:

Set-g default-terminal "screen-256color"

But wait! Modifying TERM variables is actually a dangerous + tricky thing, especially if you use things like screen/tmux (see tmux FAQ). Moreover, you are likely to use more than one terminal emulator / tty, non-GNOME Terminal may not support 256colors, or even not xterm at all, so setting TERM may cause terminfo errors.

It took a long time to figure out when, under what order, the configuration files were loaded. Finally, the best solution is selected, which is to add this paragraph to .bashrc:

The code is as follows:

If [($COLORTERM = = gnome-terminal | | $(cat / proc/$PPID/cmdline) = = * gnome-terminal*)

& & $TERM! = screen*]]; then

Export TERM=xterm-256color

Fi

This is set to xterm-256color only when GNOME Terminal is not in a screen/tmux session. In addition, if you use some keyboard shortcuts and other ways to start Byobu/screen/tmux quickly, then be careful to check that the corresponding commands for keyboard shortcuts should be similar to: env TERM=xterm-256color byobu (this kind of direct calls usually do not execute .bashrc). (in fact, the startup parameters of byobu.desktop in Archlinux's byobu package are exactly the same. )

Finally, the last picture:

At this point, the study of "how to change the color of the Linux command line terminal interface" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report