Eight practical and interesting bash command prompt lines

Source: Internet
Author: User
Tags command prompt codes time and date
Document directory
  • 1. Add a smiley face symbol to the successfully executed command.
  • 6. display the number of running tasks in the background
  • 7. Display path information
  • 8. My prompt
Eight practical and interesting bash command prompt lines

Zhao Yu

Original: http://coolshell.cn /? P = 1399 (cool shell)

 

Many people are not concerned about the importance of command line prompts. But I do not think so at all. A good command line prompt can change the way you use commands. To this end, I found some useful, excellent, and interesting bash command line prompts on the Internet. Below I will list some of my favorite command line prompts as follows.

Note-to use the following prompts, you can copy and paste the headers starting with "PS1" to your terminal. In order to make your changes take effect permanently, also paste the content to your user's ~ /. Bashrc file.

 

1. Add a smiley face symbol to the successfully executed command.

This command prompt line may be the most interesting one in the command line prompt list, but it is still useful. The idea behind this prompt is that when your command is successfully executed, you will get a smiling face as your command line prompt. Once the command execution fails, the command line prompt will change to a crying face.

Example:

Code:

PS1 = "/'If [/$? = 0]; Then ECHO/[/E [33 m/] ^_^/[/E [0 m/]; else echo/[/E [31 m/] o_o/[/E [0 m/]; FI/'[/u @/h:/W] // $"

2. Change the color of the failed command

The following command line prompt is one of my favorite command lines. Similar to the previous one, the color of the command line prompt will change after your last command fails to run, and the long path of the command will shorten the space for entering the command, this command prompt also contains the command numbers of each history bash command to facilitate re-extraction and running.

Example:

Code:

PS1 = "/[/033 [0; 33 m/] [/!] /'If [[/$? = "0"]; then Echo "// [// 033 [32 m //]"; else echo "// [// 033 [31 m //]"; FI/'[/u. /h:/'If [['pwd | WC-c | tr-d "" '> 18]; then Echo "// W "; else echo "// W"; FI/']/$/[/033 [0 m/] "; echo-ne"/033] 0; 'hostname-s ': 'pwd'/007 ″'

3. multiline prompt

If you like the type of person with complete information in the command line prompt, there will be a command line prompt below for you. The command line prompt contains the date/time, full path, user, host, activity terminal, and even the number of files and occupied space.

Example:


Code:

Prompt_command = 'ps1 = "/n/[/033 [35 m/]/$ (/bin/date) /n/[/033 [32 m/]/W/n/[/033 [1; 31 m/]/u @/h:/[/033 [1; 34 m/]/$ (/usr/bin/tty |/bin/sed-E's:/dev/: '):/[/033 [1; 36 m/]/$ (/bin/LS-1 |/usr/bin/WC-L |/bin/SED's: G ') files/[/033 [1; 33 m/]/$ (/bin/LS-lah |/bin/grep-M 1 Total |/bin/SED's/total //') b/[/033 [0 m/]->/[/033 [0 m/] "'

 

4. multi-color prompt

This command line prompts that apart from using different colors to differentiate different information, it is not very special. As you can see, it provides the time, user name, host name, and current directory. Very little information, but very practical.

Example:

Code:

PS1 = "/[/033 [35 m/]/t/[/033 [m/]-/[/033 [36 m/]/u/[/033 [m /] @/[/033 [32 m/]/h: /[/033 [33; 1 m/]/W/[/033 [m/]/$"

 

5. display the complete path

This is a good, concise, minimum 2-line prompt (plus the empty lines on top ). In the first line, you can get a full path information, and in the second line, you can get a user name. If you are not happy with the empty line of each command prompt line, you just need to remove the first/N and it will be OK.

Example:

Code:

PS1 = "[/[/033 [32 m/]/W]/[/033 [0 m/]/n/[/033 [1; 36 m/]/u/[/033 [1; 33 m/]->/[/033 [0 m/]"

 

6. display the number of running tasks in the background

This is another two-line prompt, but the two-line prompt has more information we didn't have before. The first line shows information such as user @ host and full path. In the second line, we can obtain the command execution history number and the number of running tasks in the background.

Example:

 

Code:

PS1 = '/[/E [1; 32 m/]/u @/h:/[/E [m/]/[/E [1; 37 m/]/W/[/E [m/]/n/[/E [1; 33 m/] hist :/! /[/E [0; 33 m/]/[/E [1; 31 m/] jobs:/J/$/[/E [m/]'

 

7. Display path information

This is a very dazzling design. You can obtain the user/host, number of running tasks, and time and date information from the first line of the command line prompt. In the second line, we can get the number of files in the current directory and the disk space they occupy.

Example:

 

Code:

PS1 = "/n/[/E [30; 1 m/]/[/016/] L/[/017/] (/[/E [34; 1 m/]/u @/h/[/E [30; 1 m/])-(/[/E [34; 1 m/]/J/[/E [30; 1 m/])-(/[/E [34; 1 m/] // @/D/[/E [30; 1 m/])->/[/E [30; 1 m/]/n/[/016/] M/[/017/]-(/[/[/E [32; 1 m/]/W/[/E [30; 1 m/])-(/[/E [32; 1 m/]/$ (/bin/LS-1 |/usr/bin/WC-L |/bin/SED's: G') files, /$ (/bin/LS-lah |/bin/grep-M 1 Total |/bin/SED's/total // ') B/[/E [30; 1 m/])->/[/E [0 m/]"

8. My prompt

The command prompt line is my favorite command prompt line. It is a modification of #7. The command prompt line only contains the information that I want to know most, thus saving space for it. I prefer the two-line style, because this not only allows me to see the full path information, but also does not affect the visual space of my command input.

Example:

Code:

PS1 = "/n/[/E [32; 1 m/] (/[/E [37; 1 m/]/u/[/E [32; 1 m/])-(/[/E [37; 1 m/] jobs:/J/[/E [32; 1 m/]) -(/[/E [37; 1 m/]/W/[/E [32; 1 m/])/n (/[/E [37; 1 m/]! /! /[/E [32; 1 m/])->/[/E [0 m/]"

If you are willing to share your command prompt line, add these command prompt codes to the comments below.

PS1 = "/n/[/033 [35 m/]/$ (/bin/date) /n/[/033 [32 m/]/W/n/[/033 [1; 31 m/]/u @/h:/[/033 [1; 34 m/]/$ (/usr/bin/tty |/bin/SED

-E's:/dev/: '):/[/033 [1; 36 m/]/$ (/bin/LS-1 |/usr/bin/WC-L |/bin/SED's: G ') files/[/033 [1; 33 m/]/$ (/bin/LS-lah |/bin/grep-M 1 Total |/bin/SED's/total //') b/[/033 [0 m/]->/[/033 [0 m/]"

Source

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.