Linux command
su 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Switch
su
Switch
su [username]
Switch
su - [username]
Execute
su - [username] -c "[command]"
Switch
su -s /[path/to/shell] [username]
说明
su (substitute user) allows running a shell or command as a different user. Without a username, it switches to the root user by default. The difference between su and su - is that the latter provides a full login environment, resetting environment variables and changing to the target user's home directory.
参数
- -, -l, --login
- Provide a login shell environment
- -c, --command _command_
- Pass a single command to the shell
- -s, --shell _shell_
- Use the specified shell instead of the default
- -p, --preserve-environment
- Preserve the entire environment
- -m
- Preserve environment (same as -p)
- -g, --group _group_
- Specify the primary group
FAQ
What is the su command used for?
su (substitute user) allows running a shell or command as a different user. Without a username, it switches to the root user by default. The difference between su and su - is that the latter provides a full login environment, resetting environment variables and changing to the target user's home directory.
How do I run a basic su example?
Run `su` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -, -l, --login do in su?
Provide a login shell environment