linux下/etc/profile、/etc/bashrc、~/.bashrc 和~/.bash_profile文件的区别
这个一定要理解登录式shell和非登录式shell的区别,前者是完全切换用户,后者是不完全,就算切换过来了,你pwd时家目录还是之前的家目录,所以
登录式顺序为:/etc/bashrc---/etc/profile.d/*.sh----~/.bash_profile---~/.bashrc_profile----~/.bashrc-----/etc/bashrc
非登录式:~/.bashrc-----/etc/bashrc-/etc/profile.d/*.sh
-
/etc/profile:
该文件登录操作系统时,为每个用户设置环境信息,当用户第一次登录时,该文件被执行。也就是说这个文件对当前每个shell都有效,如果此时su 其他用户没有- ,则切过去的用户无法使用你alias的别名,应为是他是登陆时就产生的,用于获取系统的环境信息。 -
/etc/bashrc:为每一个运行bash shell的用户执行此文件,当bash shell被打开时,该文件被读取。也就是说,当用户shell执行了bash时,就运行这个文件,无论你su切换其他用户加-还是不加-alias都有效。
3、`/.bashrc该文件存储的是专属于个人bash shell的信息,当登录时以及每次打开一个新的shell时,执行这个文件。在这个文件里可以自定义用户专属的个人信息。
1、环境变量配置原因
环境变量:指定一个目录,运行软件或程序的时候,相关程序会按照目录寻找相关文件
原因:使你可以在非安装目录运行软件
2、环境变量的设置方法
(1) 控制台,仅临时有效,仅针对于当前shell
- $PATH="$PATH:/opt/tomcat"
需要给某个用户权限只需要在其个人主目录想修改即可。修改方法类似于/etc/profile文件
3、~/.bashrc、~/.bash_profile、~/.bash.profile和/etc/bashrc和/etc/profile的区别
1 # /etc/profile 2 3 # System wide environment and startup programs, for login setup 4 # Functions and aliases go in /etc/bashrc 5 6 # It's NOT a good idea to change this file unless you know what you 7 # are doing. It's much better to create a custom.sh shell script in 8 # /etc/profile.d/ to make custom changes to your environment, as this 9 # will prevent the need for merging in future updates.
②/ etc / bashrc:
为每一个运行bash shell的用户执行此文件,当bash shell被打开时,该文件被读取。也就是说,当用户shell执行了bash时,运 行这个文件。
1 # /etc/bashrc 2 3 # System wide functions and aliases 4 # Environment stuff goes in /etc/profile 5 6 # It's NOT a good idea to change this file unless you know what you 7 # are doing. It's much better to create a custom.sh shell script in 8 # /etc/profile.d/ to make custom changes to your environment, as this 9 # will prevent the need for merging in future updates.
③〜/ .bashrc 该文件存储的是专属于个人bash shell的信息,当登录时以及每次打开一个新的shell时,执行这个文件。在这个文件里可以自定义用户专属的个人信息。
④~/.bash_profile:每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登录时,该 文件仅仅执行一次!默认情况下,他设置一些环境变量,执行用户的.bashrc文件.
1、在登录时,操作系统定制用户环境时使用的第一个文件就是 /etc/profile ,此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行。
2、在登录时操作系统使用的第二个文件是 /etc/environment ,系统在读取你自己的profile 前,设置环境文件的环境变量。
3、在登录时用到的第三个文件是.profile文件,每个用户都可使用该文件输入专用于自己使用的shell信息,,该 文件仅仅执行一次!默认情况下,他设置一些环境变量,执行用户的.bashrc文件。/etc/bashrc:为每一个运行bash shell的用户执行此文件。当bash shell 被打开时,该文件被读取。
cankao:https://blog.csdn.net/jirryzhang/article/details/70833544
相关文章
- Linux基础知识第四讲,文件内容命令
- 在Linux服务器关机前向用户显示一条自定义消息
- [转载]Linux常用的可插拔认证模块(PAM)pam_limits.so、pam_rootok.so和pam_userdb.so的详解
- linux命令学习之:chown
- Linux - xshell 链接CentOS 设置高亮
- Linux+Redis实战教程_day02_2、redis简述及安装与启动
- linux系统优化基础
- 每天学点Linux命令之grep 和 wc命令 ---(6/25)
- arg...(linux)在Windows中的使用
- 【Hack The Box】Linux练习-- Frolic
- Linux链接库二(动态库,静态库,库命名规则,建立个没有版本号的软连接文件)
- linux下的so、o、lo、a、la文件的区别
- linux查看rpm包创建的所有目录和文件
- 对比Linux系统和Windows系统哪个更好
- Linux下查看进程打开的文件句柄数和如何修改
- Windows Linux 删除N天之前的文件脚本