CentOS7下的 /etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc 笔记2208300059

CentOS7下的 /etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc

它们都是脚本, 都会在登录系统时(第一层shell(barh))执行
/etc/profile、~/.bash_profile 只会在每次登录系统(顶层shell)时执行一次
/etc/bashrc、~/.bashrc 在每次创建子bash时都会触发
/etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc 都可用来配置环境变量 , 但作用域不同
/etc/profile、/etc/bashrc 是系统级别的
~/.bash_profile、~/.bashrc 是用户级别的
/etc/bashrc 是被 ~/.bashrc 调用的
而 ~/.bashrc 是被 ~/.bash_profile 调用的
~/.bash_profile 调用 ~/.bashrc 调用 /etc/bashrc



/etc/profile

用来设置系统环境参数,比如$PATH
对所有用户生效的。

cat /etc/profile

sudo vi /etc/profile



/etc/bashrc

设置bash相关的内容,
对系统内所有用户生效。
只要用户运行bash命令,那么这里面的东西就在起作用。

cat /etc/bashrc

sudo vi /etc/bashrc



~/.bash_profile = $HOME/.bash_profile

用来设置一些环境变量,功能和/etc/profile 类似,作用域只针对当前用户
~波浪号代表用户在/Home目录下的主文件夹

cat ~/.bash_profile

vi ~/.bash_profile

cat $HOME/.bash_profile

vi $HOME/.bash_profile



~/.bashrc = $HOME/.bashrc

作用类似于/etc/bashrc, 只是针对当前用户,不对其他用户生效。
~波浪号代表用户在/Home目录下的主文件夹

cat ~/.bashrc

vi ~/.bashrc

cat $HOME/.bashrc

vi $HOME/.bashrc

$HOME/.bash_profile 调用 $HOME/.bashrc 调用 /etc/bashrc
在这里插入图片描述
在这里插入图片描述




对比 profile 和 bashrc

一个试验
在四个文件种分别加入 ------echo ‘该文件名’
然后登录系统,新开bash,新开sh
在这里插入图片描述

👆可看出:

  1. 执行顺序是 /etc/profile , /etc/bashrc , ~/.bashrc , ~/.bah_profile
  2. 运行bash命令的时候 , 会触发 /etc/bashrc和~/.bashrc  ,  不会触发 /etc/profile和~/.bash_profile
  3. 运行sh命令的时候, 都不会触发
    在这里插入图片描述
    👆可看出
    root登录时,会执行/etc/profile和/etc/bashrc , 不会执行z用户的.bashrc和.bash_profile




  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kfepiza

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值