su switch user

$ ls

/home/scott/libby

$ whoami

scott

$ su gromit

Password:

$ whoami

gromit

$ ls

/home/scott/libby

这里su改变用户时目录并没有发生变化。从本质上来说,你已经变成了 gromit ,但使用的仍然是 scott 的环境变量。

su [-|-l|--login] 此选项可以使用户切换到新用户时,等同于新用户从控制台登录。如下例:

$ ls

/home/scott/libby

$ whoami

scott

$ su -l gromit

Password:

$ whoami

gromit

$ ls

/home/gromit