su 命令默认参数即为 root ,因此 su root 与 su - root 区别即为 su 与 su - 的区别。
探索
解释
su - root is the same as su -
just like login as root, then the shell is login shell,
which mean it will expericene a login process,
usually .bash_profile and .bashrc will be sourced
su root is the same as su
like you open an interactive shell in root name,
then only .bashrc will be sourced.测试
cd /home/kane
su root
pwd
/home/kane
exit
su - root
pwd
/root 总结
su只获得根用户的执行权限,不能获得根用户的环境变量。su -是切换到根用户并获得根用户的环境变量及执行权限。
区别实质
实质区别就在于是否执行 .bash_profile,即 su 只能获得 root 的执行权限,不能获得环境变量;su - 是切换到 root 并获得 root 的环境变量及执行权限。
附录
参考链接
本文由 柒 创作,采用 知识共享署名4.0
国际许可协议进行许可。
转载本站文章前请注明出处,文章作者保留所有权限。
最后编辑时间: 2018-06-09 07:07 AM