Linux系统中PATH环境变量的查看与设定1.查看环境变量
(1).查看单个环境变量
[root@server3 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
(2)查看所有环境变量
[root@server3 ~]# env
(3)查看所有本地定义的环境变量
环境变量path误删有影响吗
[root@server3 ~]# set
2.设置环境变量
(1).export命令
⽣效⽅法:⽴即⽣效
有效期限:临时改变,只能在当前的终端窗⼝中有效,当前窗⼝关闭后就会恢复原有的path配置
⽤户局限:当前⽤户
[root@server3 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@server3 ~]# export PATH=/usr/local/nginx/bin:$PATH
[root@server3 ~]# echo $PATH
/usr/local/nginx/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
#还原:
[root@server3 ~]# exit
logout
Connection to 172.25.66.3 closed.
[root@foundation66 bin]# ssh root@172.25.66.3
root@172.25.66.3's password:
Last login: Sun Apr 14 10:40:18 2019 from foundation66.localdomain [root@server3 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
(2).修改~/.bashrc⽂件
⽣效⽅法:1.关闭当前终端窗⼝,重新打开⼀个新终端窗⼝就能⽣效
2.输⼊“source ~/.bashrc”命令,⽴即⽣效
有效期限:永久有效
⽤户局限:当前⽤户
[root@server3 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
#  ~ 即为 /root
[root@server3 ~]# vim  ~/.bashrc
>>>##
export PATH=/usr/local/nginx/bin:$PATH
[root@server3 ~]# source ~/.bashrc
[root@server3 ~]# echo $PATH
/
usr/local/nginx/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin [root@server3 ~]# exit
logout
Connection to 172.25.66.3 closed.
[root@foundation66 bin]# ssh root@172.25.66.3
root@172.25.66.3's password:
Last login: Sun Apr 14 10:46:22 2019 from foundation66.localdomain [root@server3 ~]# echo $PATH
/usr/local/nginx/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
删除: export PATH=/usr/local/nginx/bin:$PATH
[root@server3 ~]# source ~/.bashrc
[root@server3 ~]# echo $PATH
/usr/local/nginx/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@server3 ~]# exit
logout
Connection to 172.25.66.3 closed.
[root@foundation66 bin]# ssh root@172.25.66.3
root@172.25.66.3's password:
Last login: Sun Apr 14 10:55:54 2019 from foundation66.localdomain
[root@server3 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
(3)修改.bash_profile⽂件
⽣效⽅法:source命令
有效期限:永久有效
⽤户局限:当前⽤户
[root@server3 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@server3 ~]# vim .bash_profile
>>>##
添加  :/usr/local/nginx/bin
[root@server3 ~]# source .bash_profile
[root@server3 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin:/usr/local/nginx/bin [root@server3 ~]# exit
logout
Connection to 172.25.66.3 closed.
[root@foundation66 bin]# ssh root@172.25.66.3
root@172.25.66.3's password:
Last login: Sun Apr 14 11:05:47 2019 from foundation66.localdomain
[root@server3 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/nginx/bin
删除  :/usr/local/nginx/bin
[root@server3 ~]# source .bash_profile
[root@server3 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/nginx/bin:/root/bin [root@server3 ~]# exit
logout
Connection to 172.25.66.3 closed.
[root@foundation66 bin]# ssh root@172.25.66.3
root@172.25.66.3's password:
Last login: Sun Apr 14 11:22:46 2019 from foundation66.localdomain
[root@server3 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
(4)修改/etc/profile⽂件
⽣效⽅法:source命令
有效期限:永久有效
⽤户局限:对所有⽤户
[root@server3 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@server3 ~]# vim /etc/profile
>>>##
export PATH=/usr/local/nginx/bin:$PATH
[root@server3 ~]# source /etc/profile
[root@server3 ~]# echo $PATH
/usr/local/nginx/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
#还原:
[root@server3 ~]# vim /etc/profile
>>>##
删除: export PATH=/usr/local/nginx/bin:$PATH
[root@server3 ~]# source /etc/profile
[root@server3 ~]# echo $PATH
/usr/local/nginx/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@server3 ~]# exit
logout
Connection to 172.25.66.3 closed.
[root@foundation66 bin]# ssh root@172.25.66.3
root@172.25.66.3's password:
Last login: Sun Apr 14 10:59:01 2019 from foundation66.localdomain
[root@server3 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
3.常⽤的环境变量
PATH        #决定了shell将到哪些⽬录中寻命令或程序
HOME        #当前⽤户主⽬录
HISTSIZE  #历史记录数
LOGNAME    #当前⽤户的登录名
HOSTNAME  #指主机的名称
SHELL      #当前⽤户Shell类型
LANGUGE    #语⾔相关的环境变量,多语⾔可以修改此环境变量MAIL      #当前⽤户的邮件存放⽬录
PS1        #基本提⽰符,对于root⽤户是#,对于普通⽤户是$

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。

发表评论