手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

Linux 命令提示符显示全路径prompt配置

时间:2024-10-14 09:16:24

在使用linux shell窗口的时候大家都总喜欢根据自己的使用习惯配置左侧命令提示符的内容,显示当前目录名字,当前目录的全路径等等,下面我就根据自己的使用经验详细说明一下配置过程。

工具/原料

Linux

电脑

检查Shell版本

1、用下面的命令输出查看shell版本,不同的shell版本对应有不同的配置方法。echo $SHELL

Bash shell

1、Bash shell配置命令提示符的变量是PS1,同时它还提供了一些特殊的变量来支持提示符的设置,所以只需要根据需要配置PS1的值即可实现Shell命令提示符的趑虎钾缫更改。\d :代表日期,格式为 Weekday Month Date,例如 "Mon Aug 1"\H :完整的主机名称。\h :仅取主机名称的第一个名字。如下图所示\t :显示时间,为 24 小时格式。\T :显示时间,12 小时的时间格式。\A :显示时间,24 小时格式, HH:MM\u :目前使用者的账号名称;\v :BASH 的版本信息;\w :完整的工作目录名称。家目录会以 ~ 取代;\W :利用 basename 取得工作目录名称,所以仅会列出最后一个目录名。\# :下达的第几个指令。\$ :提示字符,如果是 root 时,提示字符为 # ,否则就是 $ 。例如:>> PS1='\w >>'~ >>~ >>具体结果如下图所示:

Linux 命令提示符显示全路径prompt配置

TC shell

1、TCshell 配置命令提示符的变量是prompt,同时它也提供了一些特殊的变量来支持提示符的设置,所以我们只需要更改prompt变量的值来改命令提示符。%/ The current working directory.%~ The current working directory, but with one's home directory represented by `~' and other users' home directories represented by `~user' as per Filename substitution. `~user' substi- tution happens only if the shell has already used `~user' in a pathname in the current ses- sion.%c[[0]n], %.[[0]n] The trailing component of the current working directory, or n trailing components if a digit n is given. If n begins with `0', the number of skipped components precede the trailing component(s) in the format `/<skipped>trail- ing'. If the ellipsis shell variable is set, skipped components are represented by an ellipsis so the whole becomes `...trailing'. `~' substitution is done as in `%~' above, but the `~' component is ignored when counting trailing components.%C Like %c, but without `~' substitution.%M The full hostname (e.g. jaguar.apple.com).%m The hostname up to the first `.' (e.g. jaguar).%n The user name.例:>> set prompt="%~ >> "~ >>~ >>~ >> set prompt="%/ >> "/home/guest >>/home/guest >>具体示例如下图

Linux 命令提示符显示全路径prompt配置

Kshell

1、Kshell配置命令提示符的变量是PS1, 它把提示符变量PS1作为一个特殊的变量看待,所以我们只需要更改这个变量就可以完成对命令提示符的配置。>> PS1="$PWD >>"/home/guest/script >>/home/guest/script >>

Linux 命令提示符显示全路径prompt配置
© 手抄报圈