Linux系统命令su和su – 区别验证

以下内容为reed个人见解,不保证内容的准确性,仅供参考讨论,如有错误之处,万望提出!由于工作需要,Linux下经常在各个用户之间切换,所以经常用到这个命令:su -,因为一直用这个命令,所以也没留意su后面为什么要加一个横杠,不加的话有什么区别。今天脑海里一直浮现su和su – 有什么区别,既然有疑问,就要解决之,哪怕是最基本最简单的问题。

————————————————————————————-A.用info su命令查看帮助如下(不用翻译啦,大概看的明白吧):1)默认的su,也就是不加参数By default, `su’ does not change the current directory. It sets theenvironment variables `HOME’ and `SHELL’ from the password entry forUSER, and if USER is not the super-user, sets `USER’ and `LOGNAME’ toUSER. By default, the shell is not a login shell.2)su加’-‘/’-l’/’–login’参数`-‘`-l’`–login’Make the shell a login shell. This means the following. Unset allenvironment variables except `TERM’, `HOME’, and `SHELL’ (whichare set as described above), and `USER’ and `LOGNAME’ (which areset, even for the super-user, as described above), and set `PATH’to a compiled-in default value. Change to USER’s home directory.Prepend `-‘ to the shell’s name, intended to make it read itslogin startup file(s). Additionaly `DISPLAY’ and `XAUTHORITY’environment variables are preserved as well for PAM functionality.

B.再看看2个例子:1.例子1,现有reed普通用户,,用su切换root用户。

例子1用[su]命令切换root用户,从例子看出的确是切换到root用户了,但是工作目录和环境变量竟然还是reed的,用useradd命令竟然提示找不到。

不求与人相比,但求超越自己,要哭就哭出激动的泪水,要笑就笑出成长的性格。

Linux系统命令su和su – 区别验证

相关文章:

你感兴趣的文章:

标签云: