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.
suis a program used to switch to another user. If you executesu <user>you start a shell session as another user.sudoallows you to run a single command as the root user.sudo suallows you to runsuas the root. If you executesudo su <user>you start a shell session as the user.
Then,
sudo su lswill start a shell as thelsuser, if it exists.sudo lswill 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
-
sudoallows you to do anythingsucan do, and more.suhas been obsoleted bysudo. – Johan Myréen Sep 18 '17 at 07:57