su sum su --classified

The biggest essential difference between the su command and the su -command

 

The biggest essential difference between the su command and the su -command is:
The former just switches the root identity, but the shell environment is still the shell of ordinary users;
The latter even switches the user and the shell environment to the root identity.
The PATH environment variable error will not occur only if the Shell environment is switched.
After su is switched to the root user, pwd it and find that the working directory is still the working directory of the ordinary user;
After switching with the su - command, the working directory becomes the root working directory.
Use the echo $PATH command to see how the environment variables differ between su and su -after.
 
xin@xin-VirtualBox:/var/www$ su
密码:
root@xin-VirtualBox:/var/www# pwd
/var/www
root@xin-VirtualBox:/var/www# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
root@xin-VirtualBox:/var/www# exit
exit
xin@xin-VirtualBox:/var/www$ su -
密码:
root@xin-VirtualBox:~# pwd
/root
root@xin-VirtualBox:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
root@xin-VirtualBox:~#
And so on, to switch from the current user to another user, you should use the su - command.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326438985&siteId=291194637