Bash PS1 in Linux

Source: Internet
Author: User

Bash PS1 in Linux
Chatting with a friend, he said he had such a confusion when using Ubuntu: using the cd command in bash, after entering some deep directories, or after directories with very long names, the bash command prompt is so long that every command will wrap

Hadoop-mapred @ hdp32:/etc/opt/directorynameisfuckingsolong/my/name/is/spazzzz $

This is similar to the above situation... this is the problem with the bash command prompt variable PS1. Here PS1 uses the complete path name:
 
 
  1. echo $PS1 
  2. \[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$ 
Here, the parameter \ w is used to show the complete path. If you only want to display the current path, change w to W, and the problem is solved! (As for where to modify it, you need to check the linux release, some of which are in the/etc/profile and some are in ~ /. Bash_profile) as in the previous situation, the display becomes

Hadoop-mapred @ hdp32: spazzzz $

This is not much better.

PS: Meaning of some variables

\ D: represents the date, in the format of weekday month date, for example, "Mon Aug 1" \ H: complete host name. The name is fc4.linux \ h: only the first name of the host. In the preceding example, the name is fc4 ,. linux is omitted \ t: The display time is in the 24-hour format, for example, HH: MM: SS \ T: The display time is in the 12-hour format \ A: The display time is in the 24-hour format: HH: MM \ u: Account name of the current user \ v: BASH version \ w: complete working directory name. In the home directory ~ Replace \ W: Use basename to get the name of the working directory. Therefore, only the last directory \ # is listed. For example, if it is root, the prompt is: #, the common user is: {debian_chroot: + ($ debian_chroot)}, which means that if the debian_chroot file exists in/etc, the contents of the debian_chroot file are appended to the command 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.