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 output effect of Linux shell

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

What this article shares with you is about how to change the output effect of Linux shell. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Linux shell output effect can be changed, before reading this article is really do not know, think this article is still very meaningful, here reprint, a detailed description of the Linux shell output effect of the change of parameters, using these parameters can change what.

The color of the text terminal can be generated using a "ANSI unconventional character sequence". For example:

Echo-e "\ 033 [4437 witch 5m ME\ 033 [0m COOL"

The above command sets the background to blue, the foreground white, flashes the cursor, outputs the character "ME", then resets the screen to the default setting, and outputs the character "COOL". " E "is an option for the command echo, which is used to activate the parser for special characters." \ 033 "Boot unconventional character sequence." M "means to set the property and then end the unconventional character sequence, and the really valid characters in this example are" 44 / 44 / 37 / 5 "and" 0 ".

The combination of different colors can be generated by modifying "44th / 37th / 5". The numerical value has nothing to do with the order before and after the coding. The encodings you can choose are as follows:

Coded color / action

0 reset properties to default settings

1 set bold

2 set half brightness (simulate the color of the color monitor)

4 set the underline (simulate the color of the color monitor)

5 set flicker

7 set the reverse image

22 set general density

24 turn off the underline

25 turn off flashing

27 turn off reverse image

30 set the black foreground

31 set the red foreground

32 set the green foreground

33 set brown foreground

34 set the blue foreground

35 set purple foreground

36 set cyan foreground

37 set the white foreground

38 underline the default foreground color

39 turn off underlining on the default foreground color

40 set a black background

41 set the red background

42 set the green background

43 set brown background

44 set the blue background

45 set purple background

46 set cyan background

47 set a white background

49 set the default black background

Other interesting codes include:

\ 033 [2J clear screen

\ 033 [0Q turn off all keyboard lights

\ 033 [1Q set "scroll lock" indicator (Scroll Lock)

\ 033 [2Q set Numeric Lock indicator (Num Lock))

\ 033 [3Q set "uppercase lock" indicator (Caps Lock)

\ 033 [15Plus 40H move the shutdown to line 15, column 40

\ 007 beeper beep

# # #

RedHat font and background color change method:

Command:

PS1= "[\ e [32th 1m\ u @\ h\ W]\\ $"

Or

For the difference between export PS1= "[32th 1m\ u @\ h\ W]\\ $", please see the relevant information on the environment variables.

Explanation:

\ e [32th 1m: this is the escape character that controls the font and background color. 30x 37 is the font color and 40th 47 is the background color.

In the example, the position of the 32th 1m number can be changed, such as\ e [1x 32m, if it is in the X environment, you can change the range of 1: 0x 10, which may be useless: 0 or not write (\ e [0x 32m or\ e [; 32m) show light color, 1: highlight 4: underline. If the effect of the change is not good, but can not restore the original, then do not write the number in front of m, such as\ e [32 [32] m, or log out and log in again.

\ u\ h\ W: these are some escape characters, which are explained in detail below:

\ d: represents a date in the format of weekday month date, for example: "Mon Aug 1"

\ H: full host name. For example, if my machine name is fc4.linux, then this name is fc4.linux

\ h: only take the * name of the host. As in the example above, fc4,.linux is omitted.

\ t: display time in 24-hour format, such as HH:MM:SS

\ t: the display time is in 12-hour format

\ a: display time is 24 hours format: HH:MM

\ U: current user's account name

\ v: version information of BASH

\ w: full working directory name. The home catalogue will be replaced by ~

\ W: use basename to get the working directory name, so only one directory will be listed

\ #: the number of orders issued

\ $: prompt character. If it is root, the prompt is: #, and the average user is: $

\ n: create a new row

Fonts are not limited to one color, but can have multiple colors:

PS1= "[\ e [32nt1m\ u @\ e [35trans1m\ h\ e [31trans1m\ W]\ $"

The above two commands will become invalid after logging out, and they will take effect in the following ways:

Vi / etc/profile

In "export PATH." Add a line below: export PS1= "[\ e [32th 1m\ u @\ h\ W]\\ $"

Log out and log in again, and it succeeds. If it doesn't work, try using the source / etc/profile command, or restart the machine directly.

How about here Linux shell output effect can be changed according to your preferences.

The above is how to change the output effect of Linux shell. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

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