I saw some command such as sudo su ls
, and I just wonder what's the deference between sudo ls
?
Asked
Active
Viewed 1.5k times
3

Peco
- 161
- 1
- 2
- 5
-
1This is a good explanation of the difference between sudo, su, sudo -i, sudo su, etc. – nullmeta Sep 18 '17 at 02:06
-
A similar question is https://unix.stackexchange.com/questions/145873/ . – JdeBP Sep 18 '17 at 05:08
1 Answers
5
In fact, the commands you mentioned perform two different tasks.
su
is a program used to switch to another user. If you executesu <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 runsu
as the root. If you executesudo su <user>
you start a shell session as the user.
Then,
sudo su ls
will start a shell as thels
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
-
sudo
allows you to do anythingsu
can do, and more.su
has been obsoleted bysudo
. – Johan Myréen Sep 18 '17 at 07:57