以下内容为reed个人见解,不保证内容的准确性,仅供参考讨论,如有错误之处,万望提出!
由于工作需要,Linux下经常在各个用户之间切换,所以经常用到这个命令:su -,因为一直用这个命令,所以也没留意su后面为什么要加一个横杠,不加的话有什么区别。今天脑海里一直浮现su和su - 有什么区别,既然有疑问,就要解决之,哪怕是最基本最简单的问题。-------------------------------------------------------------------------------------
A.用info su命令查看帮助如下(不用翻译啦,大概看的明白吧):
1)默认的su,也就是不加参数
By default, `su" does not change the current directory. It sets the
environment variables `HOME" and `SHELL" from the password entry for
USER, and if USER is not the super-user, sets `USER" and `LOGNAME" to
USER. By default, the shell is not a login shell.
2)su加"-"/"-l"/"--login"参数
`-"
`-l"
`--login"
Make the shell a login shell. This means the following. Unset all
environment variables except `TERM", `HOME", and `SHELL" (which
are set as described above), and `USER" and `LOGNAME" (which are
set, even for the super-user, as described above), and set `PATH"
to a compiled-in default value. Change to USER"s home directory.
Prepend `-" to the shell"s name, intended to make it read its
login startup file(s). Additionaly `DISPLAY" and `XAUTHORITY"
environment variables are preserved as well for PAM functionality.B.再看看2个例子:
1.例子1,现有reed普通用户,用su切换root用户。[reed@linuxidc ~]$ pwd
/home/reed
[reed@linuxidc ~]$ id
uid=510(reed) gid=510(reed) groups=510(reed)
[reed@linuxidc ~]$ su口令:
[root@linuxidc reed]# pwd
/home/reed
[root@linuxidc reed]# id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
[root@linuxidc reed]# echo $PATH
/usr/kerberos/sbin:/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/java/jdk1.5.0_11/bin:/usr/local/mysql/bin:/usr/apache/bin:/home/reed/bin[root@linuxidc reed]# useradd test
bash: useradd: command not found
[root@linuxidc reed]# 例子1用[su]命令切换root用户,从例子看出的确是切换到root用户了,但是工作目录和环境变量竟然还是reed的,用useradd命令竟然提示找不到。
shell实现文件名相同路径不同的批量复制iptables使用ipt_connlimit限制连接数相关资讯 linux常用命令 Linux su命令 Linux su
- 常用的Linux命令 (今 08:47)
- Linux目录结构和常用命令 (08月29日)
- 一些 Linux 常用命令说明 (06月04日)
| - Linux 文件与目录的基本常用命令 (09月03日)
- Linux常用命令札记 (08月14日)
- Linux系统管理员常用命令实例分析 (04月11日)
|
本文评论 查看全部评论 (0)