在我的 Centos7 服务器上,我为用户提供了不同的 shell。
例如,以 root 身份运行的终端如下所示:
[root@hostname www]#
。
作为不同用户的终端看起来像bash-4.2$
。
如果我键入echo $0
以获取当前使用的 shell,我将获得/bin/bash
不同的用户和-bash
我的根用户身份。
我是否必须为不同的用户配置 shell,以使其看起来像我的 root 的 shell?
有没有办法使用 Debian 中使用的 shell ( bash
) 来查看我的位置的完整路径?(root@server:/var/www#
而不是root@server www
)。
感谢您的帮助。
答案1
听起来您的用户缺少框架文件、默认文件等.bashrc
,.bash_profile
这些文件通常会在创建用户时复制到用户的主目录中/etc/skel
。如果这些文件丢失或损坏,您可以自行复制它们。
答案2
用户的提示由 shell 变量 PS1、PS2、PS3、PS4 的值决定。
PS1 – The value of this parameter is expanded and used as the primary prompt string.
The default value for Bash is \s-\v\$ .
PS2 – The value of this parameter is expanded as with PS1 and used as the secondary
prompt string. The default value for Bash is >
PS3 – The value of this parameter is used as the prompt for the select command
PS4 – The value of this parameter is expanded as with PS1 and the value is printed
before each command bash displays during an execution trace.
通常用户仅定制 PS1。
Bash 允许通过插入一个或多个转义的特殊字符来定制这些变量:
\a : ASCII bell character
\d : The date in “Weekday Month Date” format (e.g., “Tue May 26”)
\D{format} : the format is passed to strftime(3) and the result is inserted into
the prompt string; an empty format results in a locale-specific time representation.
The braces are required
\e : Tne ASCII escape character
\h : The hostname up to the first ‘.’
\H : The full hostname
\j : The number of jobs currently managed by the shell
\l : The basename of the shell's terminal device name
\n : A newline
\s : The name of the shell
\t : The current time in 24-hour HH:MM:SS format
\T : The current time in 12-hour HH:MM:SS format
\@ : The current time in 12-hour am/pm format
\A : The current time in 24-hour HH:MM format
\u : The username of the current user
\v : The current version of bash (e.g., 2.00)
\V : The current release of bash, version and patch level (e.g., 4.12.0)
\w : The current working directory, with $HOME abbreviated with a tilde
\W : The basename of the current working directory, with $HOME abbreviated
with a tilde
\! : The history number of this command
\# : The command number of this command
\$ : If the effective UID is 0, a #, otherwise a $
\nnn : The character corresponding to the octal number nnn
\\ : A backslash
\[ : Begin sequence of non-printing characters, which could be used to embed
a terminal control sequence into the prompt
\] : End sequence of non-printing characters
例子:
fpm@fpmurphy ~]$ PS1="[\d \t \u@\h:\w ] $ "
[Sun Jul 05 23:44:17 fpm@fpmurphy:~ ] $
为了在重新启动或注销后保留自定义提示,请将提示添加到用户$HOME/.bashrc
,或使其成为所有用户的默认提示,请根据您的发行版将其添加到/etc/bashrc
或创建一个条目。/etc/bashrc.d