As a new Linux user, you may always face confusion regarding the difference between su command and su – command. But before knowing about the difference between su and su – command, we need to make ourselves familiar with Linux User Environment
Linux User Environment: Linux’s systems are multi-user environments. Whenever Linux operating system creates a new shell session(after a new terminal being started on Linux) it started preparing an environment for itself. This environment basically holds the Environment variable(Environmental depends on shell type, Bash is generally used by most of the Linux distribution).
For example, pwd command is an environmental variable.
The major difference between su & su – command
su command is an abbreviation for “substitute user” because it is used for switching to another user during a normal login session, but it is often mistaken as an abbreviation for “super user” as mainly su command is used for getting “super user” privileges as when su command is run without a username, we automatically become the superuser after giving the correct root password and after that, we will enter root’s default environment, by only typing the following command:
Now logged in as root user/super user
Directory Differences between su & su –
When we switch from one user to another user using the normal su command the current directory remains the same as of the previous user like this
When we switch from one user to another user using su — command the current directory changes to the home directory of the target user like this:
su command does not create a new User Environment (in the simple term they pretends to be the target user) but su — creates a totally new User Environment (in the simple term they are actually the target user) that we can check with environment variables like:
For su command
For su – command
For more info check the su manual by typing: