etc/profile /etc/bashrc ~/.bash_profile ~/.bashrc等配置文件区别
什么是交互式shell和非交互式shell,什么是login shell 和non-login shell。
交互式模式:就是shell等待你的输入,并且执行你提交的命令。这种模式被称作交互式是因为shell与用户进行交互。这种模式也是大多数用户非常熟悉的:登录、执行一些命令、签退。当你签退后,shell也终止了。
非交互式模式:在这种模式下,shell不与你进行交互,而是读取存放在文件中的命令,并且执行它们。当它读到文件的结尾,shell也就终止了。
login shell:就是需要输入用户名及密码登录的shell,如开机shell登陆、ssh登陆、su - username(从root切换到其他用户时无需密码)。
non-login shell:无需输入密码,如bash、su username、图形界面打开bash。
bashrc用于交互式non-login shell,而profile用于交互式login shell。系统中存在许多bashrc和profile文件
交互式登录(login)模式:主要用来设置一些系统变量
/etc/profile:(针对所有用户)此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行并从/etc/profile.d目录的配置文件中搜集shell的设置。
~/.profile:(针对个人)若bash是以login方式执行时,读取~/.bash_profile,若它不存在,则读取~/.bash_login,若前两者不存在,读取~/.profile.另外,图形模式登录时,此文件将被读取,即使存在~/.bash_profile和~/.bash_login。
~/.bash_profile:每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登录时,该文件仅仅执行一次!默认情况下,他设置一些环境变量,执行用户的.bashrc文件。
~/.bash_login:若bash是以login方式执行时,读取~/.bash_profile,若它不存在,则读取~/.bash_login,若前两者不存在,读取~/.profile。
交互式非登录(non login)模式:主要用来保存一些bash的设置
/etc/bashrc:为每一个运行bash shell的用户执行此文件.当bash shell被打开时,该文件被读取。
~/.bashrc:该文件包含专用于个人的的bash shell的bash信息,当登录时以及每次打开新的shell时,该该文件被读取。
下面是在本机的几个例子:
首先需要明确的是,读取~/.bash_profile,该文件便会去读取~/.bashrc,而~/.bashrc又会去读取/etc/bashrc。所以只要读取~/.bash_profile,便会同时读取~/.bashrc与/etc/bashrc。
1. 图形模式登录时,顺序读取:/etc/profile和~/.profile。
2. 图形模式登录后,打开终端时,顺序读取:~/.bashrc和/etc/bashrc。
3. 文本模式登录时,顺序读取:/etc/profile,~/.bash_profile,~/.bashrc和/etc/bashrc。
4. 从其它用户su到该用户,则分两种情况:
(1)如果带-l参数(或-参数,--login参数),如:su -l username,则bash是lonin的,它将顺序读取以下配置文件:/etc/profile,~/.bash_profile,~/.bashrc和/etc/bashrc。
(2)如果没有带-l参数,则bash是non-login的,它将顺序读取:~/.bashrc和/etc/bashrc并从父进程继承其环境变量。
6. 执行自定义的shell文件时,若使用“bash -l a.sh”的方式,则bash会读取行:/etc/profile,~/.bash_profile,~/.bashrc和/etc/bashrc,用sh -l a.sh调用bash,它将会执行/etc/profile以及 ~/.profile。若使用其它方式,如:bash a.sh, ./a.sh,sh a.sh,则不会读取上面的任何文件,只能从其父进程处继承环境变量,像alias等就无法继承使用了。
7. 上面的例子凡是读取到~/.bash_profile的,若该文件不存在,则读取~/.bash_login,若前两者不存在,读取~/.profile。
etc/profile /etc/bashrc ~/.bash_profile ~/.bashrc等配置文件区别的更多相关文章
- /etc/rc.local ; /etc/init.d ;/etc/profile;/etc/bashrc;~/.bash_profile;~/.bashrc;~/.bash_logout
1. /etc/rc.local 这是使用者自订开机启动程序,把需要开机自动运行的程序写在这个脚本里. 把脚本程序写在/etc/rc.d/init.d/目录下也可以 在完成 run level 3 ...
- /etc/profile /etc/bashrc ~/.bash_profile ~/.bashrc ~/.bash_logout 说明及区别
/etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行. 并从/etc/profile.d目录的配置文件中搜集shell的设置. /etc/bashrc:为每一 ...
- linux下/etc/profile /etc/bashrc /root/.bashrc /root/.bash_profile这四个配置文件的加载顺序
目录 一.关于linux配置文件 二.验证四个配置文件的加载顺序 三.结论 一.关于linux配置文件 1.linux下主要有四个配置文件:/etc/profile ./etc/bashrc ./ro ...
- 【总结】/etc/rc.d/rc.local 与 /etc/profile .bash_profile .bashrc 文件执行顺序
登陆shell与交互式非登陆shell的区别 登录shell 所谓登录shell,指的是当用户登录系统时所取的那个 shell.登录shell属于交互式shell. 登录shell将查找4个不同的启动 ...
- profile bashrc bash_profile之间的区别和联系
profile bashrc bash_profile之间的区别和联系 博客分类: Linux 执行顺序为:/etc/profile -> (~/.bash_profile | ~/.bas ...
- profile,bashrc,.bash_profile,.bash_login,.profile,.bashrc,.bash_logout浅析 Part 2
profile,bashrc,.bash_profile,.bash_login,.profile,.bashrc,.bash_logout浅析 Part 2 by:授客 QQ:103355312 ...
- profile bashrc bash_profile 之间的区别和联系
/etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集shell的设置. /etc/bashrc:为每一个 ...
- bashrc,bash_profile和/etc/profile
bashrc,bash_profile和/etc/profile 最近老出现在shell里面能跑的程序用鼠标双击app去不能跑.究其原因是因为环境变量的问题. 在类unix系统中一般有三个bash配置 ...
- Linux的环境变量.bash_profile .bashrc profile文件
Shell变量有局部变量.环境变量之分.局部变量就是指在某个Shell中生效的变量,只在此次登录中有效.环境变量通常又称“全局变量”,虽然在Shell中变量默认就是全局的,但是为了让子Shall继承当 ...
随机推荐
- RegionServer Splitting Implementation:regionServer 分裂过程分析
图片: RegionServer Split Process The RegionServer decides locally to split the region, and prepares th ...
- window下eclipse搭建hadoop环境
1 生成插件jar 1.1 安装java,ant运行环境 1.2 下载hadoop-2.5.0.tar.gz并解压到指定目录 1.3 下载hadoop2x-eclipse-plugin-master. ...
- CentOS7 部署单节点 FastDFS
准备 环境 系统:CentOS7.5 软件即依赖 libfatscommon FastDFS分离出的一些公用函数包 FastDFS fastdfs-nginx-module FastDFS和nginx ...
- LeetCode Array Easy 1. Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...
- POJ-1155 TELE 树形背包dp
dp[u][i]代表以u为根的子树选i个叶子的最大收益 那么dp[u][i]=max(dp[u][i],dp[v][k]+dp[u][i-k]-len) (1=<k<=i) 细节看代码: ...
- Codeforces 747F Igor and Interesting Numbers DP 组合数
题意:给你一个数n和t,问字母出现次数不超过t,第n小的16进制数是多少. 思路:容易联想到数位DP, 然而并不是...我们需要知道有多少位,在知道有多少位之后,用试填法找出答案.我们设dp[i][j ...
- vue Inline JavaScript is not enabled. Is it set in your options?
Vue 全家桶 vue全面介绍--全家桶.项目实例 https://www.cnblogs.com/nogodie/p/9853660.html vue项目 Inline JavaScript is ...
- dubbo管理平台安装
dubbo-admin.war可在网上百度去下载,但是我下载了好几个,发布上去服务启动都报错,这个时候大概是我们系统的JDK和编译dubbo-admin.war的JDK版本不同导致的了,强烈建议自己下 ...
- 根据ID查询实体
//查询实体 $scope.findOne=function(id){ $http.get('../brand/findOne.do?id='+id).success( function(respon ...
- HZOI2019SF
Simulation Final 坑.下午我要爆零(RP++) upd: 哈哈哈哈哈哈哈哈哈哈我真的爆零了哈哈哈哈哈哈哈哈哈哈 关于细节, T1A了但是和T3交反了哈哈哈哈哈哈哈哈哈哈 我说我真的不是 ...