(015) Linux custom prompt

Source: Internet
Author: User
Tags control characters

Fundamentals of the ten-year OPS series-Linux

Zeng Lin

Contact: [Email protected]

Website: www.jplatformx.com

Copyright: Please do not reprint the article without permission

First, Introduction

This section explains the small features of a Linux shell: the shell prompt. Like many programs in Linux, the shell prompt is highly configurable. Through the introduction, we will find the shell and terminal emulator program internal working mechanism.

Second, the decomposition of the prompt character

The system's default prompt looks as follows:

You can see that the prompt contains the user name, host name, and current working directory. The prompt is defined by an environment variable named PS1 (prompt string 1, which is the prompt string 1). Note: If the output is different from the sample, you do not need to worry about it. Each Linux distribution has a different definition of this prompt string, and some are even strangely defined.

As you can see, PS1 contains symbols that appear in the prompt, such as square brackets, the @ symbol, and the $ symbol, but the rest of the section is confusing. The escape characters used in the shell prompt are explained in detail.

Escape character Meaning
\a ASCII ringtones. When the escape character is encountered, the computer will emit a sound
\d The current date, expressed in the form of a week, month, or day, such as "Mon May 26"
\h Host name of the local machine, but without domain name
\h The full host name
\j Number of tasks in the current shell session
\l Name of the current terminal device
\ n Line break
\ r Carriage return character
\s The name of the shell program
\ t Current time (24-hour format), in hours: minutes: seconds
\ t Current time (12-hour system)
\@ Current time (12-hour format am/pm)
\a Current (24-hour system), in hours: minutes
\u User name of the current user
\v The shell version number
\v Shell's version number and issue number
\w Current working directory Name

\w

The last part of the current working directory name
\! Historical number of the current command
\# Number of commands entered in the current shell session
\$ Output "$" under Non-administrator privileges. Output "#" under Administrator privileges
\[ Flags the beginning of one or more non-printable character sequences. Used to check in nonprinting control characters so that they operate the terminal emulator in a certain way, such as moving the cursor or changing the color of the text
\] Marks the end of a non-display character sequence

(015) Linux custom prompt

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.