执行 su --help ,命令描述如下:
用法:su [选项]... [-] [用户 [参数]... ]
Change the effective user id and group id to that of USER.
-, -l, --login make the shell a login shell,
clears all envvars except for TERM,
initializes HOME, SHELL, USER, LOGNAME and PATH
-c, --command=COMMAND pass a single COMMAND to the shell with -c
--session-command=COMMAND pass a single COMMAND to the shell with -c
and do not create a new session
-f, --fast pass -f to the shell (for csh or tcsh)
-m, --preserve-environment do not reset HOME, SHELL, USER, LOGNAME
environment variables
-p same as -m
-s, --shell=SHELL run SHELL if /etc/shells allows it
--help 显示此帮助信息并退出
--version 显示版本信息并退出
单独的"-"选项隐含了-l。如果不指定用户,则假设其为root。
例子如下:
su man -c catman
Runs the command catman as user man. You will be asked for man's password unless your real UID is 0.
su man -c 'catman /usr/share/man /usr/local/man'
Same as above, but the target command consists of more than a single word and hence is quoted for use with the -c option being
passed to the shell. (Most shells expect the argument to -c to be a single word).
su -l foo
Simulate a login for user foo.
su - foo
Same as above.
su - Simulate a login for root.
注意:-或者-l 选项会重置HOME, SHELL, USER, LOGNAME and PATH环境