当前位置:网站首页>The role of /etc/profile, /etc/bashrc, ~/.bash_profile, ~/.bashrc files
The role of /etc/profile, /etc/bashrc, ~/.bash_profile, ~/.bashrc files
2022-07-31 14:26:00 【Stop losing your hair】
/etc/profile: This file sets the environment information for each user of the system. When the user logs in for the first time, this file is executed.And collect the shell settings from the configuration files in the /etc/profile.d directory.Think of system environment variables.
/etc/bashrc: Execute this file for every user running the bash shell, which is read when the bash shell is opened.
~/.bash_profile: Each user can use this file to enter shell information dedicated to their own use. When the user logs in, this file is executed only once! By default, he sets some environment variables and executes the user's.bashrc file.
~/.bashrc: This file contains bash information specific to your bash shell and is read when logging in and every time a new shell is opened.
~/.bash_logout: This file is executed every time you exit the system (exit the bash shell).
In addition, the variables (global) set in /etc/profile can act on any user, while the variables (local) set in ~/.bashrc can only inherit the variables in /etc/profile, theyIt's a "father-son" relationship.
~/.bash_profile is the interactive, login mode to enter the bash operation
~/.bashrc is the interactive non-login mode to enter the bash operation
Usually the two settings are roughly the same, so usually the former will callthe latter.
Several initialization files of bash - [Ubuntu]
(1) /etc/profile
Global (public) configuration, no matter which user is, the file will be read when logging in.
(2) /ect/bashrc
Ubuntu does not have this file, the corresponding one is /ect/bash.bashrc
It is also a global (public)
When bash is executed, no matter what it ismode, will read this file.
(3) ~/.profile
If bash is executed in login mode, read /.bash_profile, if it does not exist, read /.bash_login, if the first two do not exist, read ~/.profile.
Also, when logging in graphical mode, this file will be read even if /.bash_profile and /.bash_login exist.
(4) ~/.bash_login
If bash is executed in login mode, read /.bash_profile, if it does not exist, read /.bash_login, if the first two do not exist, read ~/.profile.
(5) ~/.bash_profile
Unbutu does not have this file by default, you can create a new one.
This file is read only when bash is executed as login.Usually this configuration file is also configured to read ~/.bashrc.
(6) ~/.bashrc
When bash is executed in non-login form, read this file.If executed in login form, this file will not be read.
(7) ~/.bash_logout
This file will only be read when it is logged out and in the form of longin.That is, when logging out in text mode, this file will be read, and when logging out in graphics mode, this file will not be read.
Here are a few examples on this machine:
When logging in in graphical mode, read sequentially: /etc/profile and ~/.profile
After logging in in graphical mode, when opening a terminal, read in sequence: /etc/bash.bashrc and ~/.bashrc
When logging in in text mode, read in sequence: /etc/bash.bashrc, /etc/profile and ~/.bash_profile
From other users su to this user, there are two cases:
(1) IfWith -l parameter (or - parameter, --login parameter), such as: su -l username, then bash is logged in, it will sequentially read the following configuration files: /etc/bash.bashrc, /etc/profile and ~/.bash_profile.
(2) If there is no -l parameter, then bash is non-login, it will read sequentially: /etc/bash.bashrc and ~/.bashrc
When logging out, or logging out of su user, if it is the longin method, then bash will read: ~/.bash_logout
When executing a custom shell file, if the "bash -l a.sh" method is used, bash will read the line: /etc/profile and ~/.bash_profile, if you use other methods, such as: bash a.sh, ./a.sh, sh a.sh (this does not belong to the bash shell), it will not read any of the above files.
The above example always reads /.bash_profile, if the file does not exist, then reads /.bash_login, if the first two do not exist, reads ~/.profile.
边栏推荐
- 技能大赛训练题:域用户和组织单元的创建
- 多智能体协同控制研究中光学动作捕捉与UWB定位技术比较
- The pre-sale of the new Hyundai Paristi is open, and safety and comfort are not lost
- OAuth2:使用JWT令牌
- The recently popular domestic interface artifact Apipost experience
- redhat/openssl generates a self-signed ca certificate and uses it
- C语言基础练(九九乘法表)与打印不同星号图案
- LeetCode旋转数组
- Shang Silicon Valley-JVM-Memory and Garbage Collection (P1~P203)
- 小试牛刀:Go 反射帮我把 Excel 转成 Struct
猜你喜欢
我把问烂了的MySQL面试题总结了一下
UnityShader入门学习(三)——Unity的Shader
为什么要分库分表?
使用NVM进行node版本切换管理
The paper manual becomes 3D animation in seconds, the latest research of Wu Jiajun of Stanford University, selected for ECCV 2022
Analysis of the startup source code of hyperf (2) - how the request reaches the controller
【redis】发布和订阅消息
Redis与分布式:集群搭建
MySQL【子查询】
The 232-layer 3D flash memory chip is here: the single-chip capacity is 2TB, and the transmission speed is increased by 50%
随机推荐
uniapp微信小程序引用标准版交易组件
Shell脚本经典案例:探测批量主机是否存活
Linux bash: redis-server: 未找到命令
MySql总结
为什么要分库分表?
AWS implements scheduled tasks - Lambda+EventBridge
Node version switching management using NVM
高等数学——常用不定积分公式
【蓝桥杯选拔赛真题46】Scratch磁铁游戏 少儿编程scratch蓝桥杯选拔赛真题讲解
Sentinel服务熔断和降级
[Blue Bridge Cup Trial Question 46] Scratch Magnet Game Children's Programming Scratch Blue Bridge Cup Trial Question Explanation
An article makes it clear!What is the difference and connection between database and data warehouse?
3.爬虫之Scrapy框架1安装与使用
OAuth2:单点登陆客户端
ML, DL, CV common problems sorting
LeetCode·304竞赛·6132·使数组中所有元素都等于零·模拟·哈希
The Selenium IDE of the Selenium test automation
推荐系统-召回阶段-2013:DSSM(双塔模型)【Embedding(语义向量)召回】【微软】
leetcode:2032. 至少在两个数组中出现的值
Selenium自动化测试之Selenium IDE