3

I saw some command such as sudo su ls, and I just wonder what's the deference between sudo ls?

Peco
  • 161
  • 1
  • 2
  • 5

1 Answers1

5

In fact, the commands you mentioned perform two different tasks.

  • su is a program used to switch to another user. If you execute su <user> you start a shell session as another user.
  • sudo allows you to run a single command as the root user.
  • sudo su allows you to run su as the root. If you execute sudo su <user> you start a shell session as the user.

Then,

  • sudo su ls will start a shell as the ls user, if it exists.
  • sudo ls will list the content of directory just like if the command was issued by the root user.

If you are interested on two equivalent commands, you may consider...

sudo bash -c "ls"       # execute "ls" as the root
sudo ls                 # execute "ls" as the root
Jaime
  • 491