zoukankan      html  css  js  c++  java
  • linux系统中su 和 su 的区别

    1、linux系统中su 和 su - 都是用于登录用于切换的命令

      su:切换用户,环境变量不变,路径不变

     su - : 切换用户,环境变量随切换用户发生改变,回到家目录

    测试 su 命令:

    [root@linuxprobe test]# ls
    [root@linuxprobe test]# whoami
    root
    [root@linuxprobe test]# pwd
    /home/test
    [root@linuxprobe test]# echo $PATH
    /root/miniconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
    [root@linuxprobe test]# su linuxprobe  ## 直接切换用户
    [linuxprobe@linuxprobe test]$ whoami
    linuxprobe
    [linuxprobe@linuxprobe test]$ pwd ## 路径未改变
    /home/test
    [linuxprobe@linuxprobe test]$ echo $PATH  ## PATH环境变量未改变
    /root/miniconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

    2、测试su - 命令

    [linuxprobe@linuxprobe test]$ exit  ## 返回root
    exit
    [root@linuxprobe test]# whoami
    root
    [root@linuxprobe test]# ls
    [root@linuxprobe test]# pwd
    /home/test
    [root@linuxprobe test]# echo $PATH
    /root/miniconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
    [root@linuxprobe test]# su - linuxprobe  ## 使用 su - 切换
    Last login: Wed Oct 21 15:28:46 CST 2020 on pts/0
    [linuxprobe@linuxprobe ~]$ whoami
    linuxprobe
    [linuxprobe@linuxprobe ~]$ pwd  ## 回到用户linxprobe家目录
    /home/linuxprobe
    [linuxprobe@linuxprobe ~]$ echo $PATH  ## PATH环境变量改变
    /usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/linuxprobe/.local/bin:/home/linuxprobe/bin
  • 相关阅读:
    函数宏实现循环左移
    函数宏判断小端
    Linux下32位与64位数据类型大小
    转:C语言嵌入式系统编程之软件架构篇
    转:详解大端小段模式
    time函数计算时间
    匈牙利命名法
    20131030
    20131029
    20131028
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/13852647.html
Copyright © 2011-2022 走看看