how to change user and run command as another user in Debian and Ubuntu

Using "su" Command!!!! I didn't use it for a long long time

This time I have a problem for running command in some user After using su many times. I saw my boss using "-" before username!!!!! Stupid Me!!! Ok, Enough for the history. Now this is the command:

$ su -, -l, --login "username"

If you want to execute commands

$ su -, -l, --login "username" -c, --command "commands" // I recommend you to use double quotes (") for sometimes we want to use arguments

for Examples

$ su - Nata-Oh , $ su -l Nata-Oh OR $ su --login Nata-Oh

$ su - Nata-Oh -c "ls -la" OR $ su - Nata-Oh --command ls

บันทึกนี้เขียนที่ GotoKnow โดย  ใน Nata's Knowledge(may be silly sometimes ^^")



ความเห็น (1)

เขียนเมื่อ 

Actually we can do with sudo for Example:

sudo -l Nata-Oh ls