For most Linux distributions, the default account is a common user. To change the system file or execute some commands, the account must be the root user. This requires switching from the current user to the root user, in Linux, the commands for switching users are Su or Su-. The following describes the essential differences between the su command and Su-command:
The former only switches the root identity, but the shell environment is still a normal user's shell; the latter switches the user to the root identity together with the shell environment. The path environment variable error does not occur only when the shell environment is switched. After Su is switched to the root user, PWD finds that the working directory is still the working directory of normal users. After Su-command is switched, the working directory is changed to the root working directory. Run the echo $ PATH command to check whether the environment variables after Su and Su are different. Similarly, to switch from the current user to another user, use the Su-command.
For example, enter:
$ Pwd
/Home/test (current user directory)
$ Su ***** (enter the password)
# PWD (view the path again)
/Home/test (or the current user directory)
However, if you change to Su-, the result is as follows:
$ Pwd
/Home/test (current user directory)
$ Su-
* ***** (Enter the password)
# PWD (view the path again)
/Root (switch to the superuser directory)