Linux terminal font color settings, path name settings, and ls command settings
Http://www.2cto.com/uploadfile/Collfiles/20140928/2014092808582563.
Linux allows you to customize System Configurations Based on your preferences.
The personal configuration file is described as follows:
Display terminals in the system default statusFor linux with purple white text (Pipi (small series), ubuntu 12.04 LTS)
In terminals without custom configuration, because all input and output are in the same color, it is inconvenient to find the execution results of some commands.
In addition to the color, the long path name in the default terminal configuration is also a pain point.
To understand the original terminal configuration, you can write it to different files, for example :~ /. Bashrc,/etc/bash. bashrc,/etc/profile files. These files
Timing:
/Etc/profile: This file sets the environment information for each user in the system. When the user logs on for the first time, this file is executed. and from/etc/profile. the configuration file in the d directory Collects shell settings. this file is called by default.
/Etc/bash. bashrcFile.
/Etc/bashrc: Execute this file for every user running bash shell. When bashshell is opened, the file is read.
~ /. Bash_profile: Each user can use this file to enter the shell information dedicated to his/her use. When a user logs on, this file is only executed once! By default, it sets some environment variables to execute the user's. bashrc file.
~ /. Bashrc: This file contains bash information dedicated to your bashshell.
~ /. Bash_logout: Execute this file every time you exit the system (exit bashshell.
You can understand that the configuration information should be written to ~ /. Bashrc file.
1.Terminal colorConfigurationTo set the terminal color, we need
~ /. BashrcFile
PS1Variable. First ~ /. Bashrc "command to open the file and find the position of the PS1 variable:
if [ "$color_prompt" = yes ]; then PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ 'else PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ 'fiWhen the color mode is enabled, the PS1 variable indicates the user name + host name + path name (long path) + $.
Eg: pipi @ ubuntu :~ $ Username-pipi; host name-ubuntu; pathname -~
The following describes how to set the PS1 variable:
Color = \ 033 [Code; foreground; Background m
For example, \ 033 [1; 31; 1 M indicates highlighted red foreground and transparent background
The following table describes how to use color settings for parsing:
---------------------------------------
Code sequence description
\ASCII Bell character (you can also type \ 007)
\ DDate in Wed Sep06 format
\ EASCII escape character (you can also type \ 033)
\ HThe first part of the Host Name (such as "mybox ")
\ HHost Name (for example, "mybox.mydomain.com ")
\ JIn this shell, the number of processes suspended by pressing ^ Z
\ LTerminal Device Name of this shell (for example, "ttyp4 ")
\ NLine Break
\ RCarriage Return
\ SShell Name (such as "bash ")
\ T24-hour time (for example, "23:01:01 ")
\ T12-hour time (for example, "11:01:01 ")
\@12-hour time with am/pm
\ UUser Name
\ VBash version (such as 2.04)
\ VBash version (including Patch Level )? /Td>;
\ WCurrent working directory (for example, "/home/drobbins ")
\ W"Basename" (for example, "drobbins") of the current working directory ")
\!Position of the current command in the History buffer zone
\#Command number (as long as you type the content, it will accumulate at each prompt)
\ $If you are not a Super User (root), insert a "$"; if you are a super user, a "#" is displayed "#"
\ XxxInsert an ASCII character represented by a three-digit number xxx (with zero instead of unused numbers, such as "/007 ")
\\Backslash
\[This sequence should appear before the Character Sequence without moving the cursor (such as the color escape sequence. It enables bash to correctly calculate the line feed.
\]This sequence should appear after the non-printable character sequence.
---------------------------------------------------------------------------------------------------------------------
Code meaning
0 OFF
1 highlighted
4 underline
5 flashes
7. Reverse display
8 invisible
---------------------------------------
Foreground background color
30 40 black
31 41 colors
32 42 colors
33 43 colors
34 44 colors
35 45 Violet colors
36 46 green colors
37 47 white
1 transparent color
---------------------------------------
Actual operations on terminal color settings:
Use the command"Cp ~ /. Bashrc ~ /. Bashrc. backup"Back up the configuration file (if you need to modify something like the configuration file, You 'd better back up the file to prevent problems such as system logon failure due to errors)
Then "gedit ~ /. Bashrc "open the file, find the code for setting the PS1 variable, and comment it out (Insert" # "before each line of code).
In this case, you can add "PS1 = '\ u @ \ h: \ w \ $'" at the end of the file (this is also the default setting of the terminal, that is, no color is added ):
#if [ "$color_prompt" = yes ]; then# PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '#else# PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '#fi
<span style="color:#999999;">#setup XIM environment, needn't if use SCIM as gtk-immodulesexport XMODIFIERS=@im=fcitxexport GTK_IM_MODULE=ximexport QT_IM_MODULE=xim</span>PS1='\u@\h:\w\$'
Add color settings to PS1:
Color = \ 033 [Code; foreground; Background m
Note:
To enclose all non-printable characters with bash escape sequences "\ [" and. (These two sequences notify bash that the enclosed characters do not occupy any space on the row, so that the automatic line feed can continue to work normally.
This is very important. Otherwise, when you set the color, your terminal line breaks will be messy)
For example, add \ [\ 033 [1; 31; 1m \] In front of \ u.
PS1 = '\ [\ 033 [1; 31; 1m \] \ u @ \ h: \ w \ $'Highlight the user name in red
Save and exit the GEdit editor. Return to the terminal and enter"Source ~ /. Bashrc".
We need to find a way to display the information in different colors. Here, the color setting ranges from the current setting command to the next color setting command. That is to say, if we only set the color before \ u, the font of the terminal should be red, not only the information items are red, but even the input commands are red. After understanding how to set the PS1 variable, you can insert a string in the PS1 variable, set different colors for each information item, or control the content displayed in the Information column: we can display the username (red), path (green), dollar sign (yellow), and command (white) as follows:
PS1 = '\ [\ 033 [1; 31; 1m \] \ u @ \ h: \ [\ 033 [1; 32; 1 m \] \ w \ [\ 033 [1; 33; 1 m \] \ $ \ [\ 033 [1; 37; 1 m \]'
The result is as follows:
2. The path name in the terminal is too longSometimes the terminal needs to open several layers of folders consecutively to access the files we need, and the path name displayed in the terminal is like a long tail.
The terminal only displays the name of the current working directory of the User:
As mentioned in the sequence description of the front edge, we can set the terminal in the PS1 variable to display only the base name of the working directory, that is, replace the lower-case w of the \ w in the PS1 variable with the upper-case W, the modified PS1 variable is:
PS1 = '\ [\ 033 [1; 31; 1m \] \ u @ \ h: \ [\ 033 [1; 32; 1 m \] \ W \ [\ 033 [1; 33; 1 m \] \ $ \ [\ 033 [1; 37; 1 m \]'
The following figure shows the effects of the two methods: (for the screenshot shortcut key ctrl + alt + a, see the tool and shortcut key settings in ubuntu)
Change ps1 to. bashrc
PS1 = '\ [\ 033 [1; 31; 1m \] \ u @ \ h: \ [\ 033 [1; 32; 1 m \] \ W \ [\ 033 [1; 33; 1 m \] \ $ \ [\ 033 [1; 37; 1 m \]'
Inaimg.cn/mw690/6d0cbb034cf623f79ed6b&690
You can find that after modifying the value of the PS1 variable, the terminal will only display the base name of the current working directory ~. Based on the above descriptions, you can also set to not display the Host Name (@ \ h removed) and show the short path name:
PS1 = '\ [\ 033 [1; 31; 1m \] \ u: \ [\ 033 [1; 32; 1m \] \ W \ [\ 033 [1; 33; 1 m \] \ $ \ [\ 033 [1; 37; 1 m \]'
Finally,
If a new terminal is opened, the User-Defined configuration is not displayed.The default configuration is displayed. You can use the source command to manually load the. bashrc file. At this time, the configuration we set is back. However, source is required every time you open the terminal.
Back to the beginning of the article, let's say
/Etc/profileThe file Collects shell settings from the configuration file in the/etc/profile. d directory. This file is called by default.
/Etc/bashrcFile, open the profile file: "sudo gedit/etc/bashrc" (note that sudo must be added here !)
In the file, there is a call to/etc/bash. the bashrc file code. As mentioned above, the profile file automatically loads bash. the bashrc file is actually implemented by the code. You can add a new code here to make the profile automatically load the user's. bashrc file to achieve the requirement that source is not required every time the terminal is opened
After saving the file, close the editor and open a new terminal. We can see that our previous configuration has been automatically loaded.
Finally, all my terminals are black. In fact, users can set their preferences directly on the terminal to achieve a translucent background, or use an image as the background:
Open a terminal, move the cursor to the top of the screen, select Edit> Configuration File preferences> background from the menu, and then set the background.
3. ls command settingsA common command on the terminal is the ls command. We can set alias in the. bashrc file to implement some custom settings of the ls command:
Alias is actually something referenced by a command. For example, in the last sentence, whenever you input the ls command in the terminal. the alias setting in the bashrc file finds the referenced command: ls -- color = auto, so every time you input "ls", it is equivalent to entering "ls -- color = auto ", the purpose of this command is to display visible files in the current directory and distinguish different types of files by color, such as folders and common files.
From: http://www.2cto.com/uploadfile/Collfiles/20140928/2014092808582563.
Ref: Change the linux terminal color
Ubuntu terminal color settings, path name settings, and ls command settings