It is an frequently used command mostly by the Linux terminal users. This tutorial will help you understand the uses of Linux su command with examples. Syntax:

su Command Examples in Linux

Let’s begin with a basic example. I’m Logged in to my system with user ‘root’, verified the identify using whoami command. Then switch to root user with su command. Again verified the identify. Things to know:

Invoke the su command without username becomes the superuser (root). Using hyphen (-) with switching invoke login shell scripts. This is used to provide an environment similar to what the user got at direct login The current environment is passed to the new shell with effective environment variables to switched user.

The sudo privileged users can also prefixed sudo with su command. like: Sometimes, you may only need to switch user to run a single or few commands only. In that condition, su provides you -c option to run command as another user without actually switching the shell.

su Command Line Options

Linux su command has only few but very useful option. These options are very useful while automating tasks with the shell scripts.