linux shell prompt

When we open a terminal or log in to the time display will prompt a long list

void@void-ThinkPad-E450:~$

Prompt typically includes user name, host name, and the current working directory path currently logged in, or the last number are based on $ # end, the average user number to $ end, only the root user by #.

Because it contains the current working directory, so when we switch the working path, the prompt will also change, when we switched to a deep-level path or directory name very, very long time will become very long Prompt , resulting in the time we need to enter the command has been input cursor to the far right end.

void@void-ThinkPad-E450:~/Homlet-Tina-H2_H3/package/allwinner/tina_multimedia/libcedarx/xmetadataretriever/include$ 

We can be controlled by changing the content of the primary prompt PS1 variable, PS1 is a bash built-in variables, the use of echo can see the definition of PS1

void@void-ThinkPad-E450:~/Homlet-Tina-H2_H3/package/allwinner/tina_multimedia/libcedarx/xmetadataretriever/include$ echo $PS1
\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$
void@void-ThinkPad-E450:~/Homlet-Tina-H2_H3/package/allwinner/tina_multimedia/libcedarx/xmetadataretriever/include$

 

\ d with "Week Month a Date " format displays the date 
\ H host name 
\ u of the current user name 
\ t by "HH: MM: SS" 24-hour format to display the current time
\ v bash version number \
W current work directory \ $ if the current user is the root of the display characters #, or $ characters when West

We can change the display contents prompt by changing the value of the variable PS1

 void@void-ThinkPad-E450:~/Homlet-Tina-H2_H3/package/allwinner/tina_multimedia/libcedarx/xmetadataretriever/include$ echo $PS1
 \[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$
 void@void-ThinkPad-E450:~/Homlet-Tina-H2_H3/package/allwinner/tina_multimedia/libcedarx/xmetadataretriever/include$

void@void-ThinkPad-E450:~/Homlet-Tina-H2_H3/package/allwinner/tina_multimedia/libcedarx/xmetadataretriever/include$PS1='\u@\h\$'
void@void-ThinkPad-E450$

 void@void-ThinkPad-E450$cd ../../../
 void@void-ThinkPad-E450$pwd
 /home/void/Homlet-Tina-H2_H3/package/allwinner/tina_multimedia
 void@void-ThinkPad-E450$

 

PS1 = ' \ u @ \ h \ $ '

 

Above the main command prompt is set to display only the username @ hostname $, so Change the working directory to any place will not affect displays the main prompt, but this method is only set valid for the current terminal, if you want the current user the need to modify the effective ~ / .bashrc

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
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

Finally, modify the definition of a PS1 save and exit.

 

Guess you like

Origin www.cnblogs.com/tid-think/p/10962243.html