su 与su -

今天在服务器上通过su hadoop切换用户,使用jps看不到启动的spark程序,找不到jps命令,原来是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.

su 后面不加用户是默认切到 root
su 是不改变当前变量
su - 是改变为切换到用户的变量
也就是说su只能获得root的执行权限,不能获得环境变量
而su -是切换到root并获得root的环境变量及执行权限
语法:
su[username]suIDIDSuswitchusersetuseridIDIDsuroot()rootsusupperuser()root使su使exit退使su su – username
一些配置文件是为你的对话线索而设立的。当你使用命令 su username时,你的对话特征和你原始的登录身份一样。如果你想要你的对话进程拥有转换后的用户 ID一致的特征,你要使用短斜杠: su – username。

你可能感兴趣的:(ubuntu)