本文最后更新于 65 天前,其中的信息可能已经过时,如有错误请发送邮件到wuxianglongblog@163.com
shell登录相关的脚本文件
bash的配置文件
按生效范围划分,存在两类:
全局配置:
/etc/profile
/etc/profile.d/*.sh
/etc/bashrc
个人配置:
~/.bash_profile
~/.bashrc
shell登录两种方式
交互式登录:
(1)直接通过终端输入账号密码登录
(2)使用“su - UserName”切换的用户
执行顺序:/etc/profile --> /etc/profile.d/*.sh --> ~/.bash_profile--> ~/.bashrc--> /etc/bashrc
非交式登录:
(1)su UserName
(2)图形界面下打开的终端
(3)执行脚本
(4)任何其它的bash实例
执行顺序:/etc/profile.d/*.sh --> /etc/bashrc-->~/.bashrc
Profile类
按功能划分,存在两类:
profile类和bashrc类
profile类:为交互式登录的shell提供配置
全局:/etc/profile, /etc/profile.d/*.sh
个人:~/.bash_profile
功用:
(1) 用于定义环境变量
(2) 运行命令或脚本
Bashrc类
bashrc类:为非交互式和交互式登录的shell提供配置
全局:/etc/bashrc
个人:~/.bashrc
功用:
(1) 定义命令别名和函数
(2) 定义本地变量
编辑配置文件生效
修改profile和bashrc文件后需生效
两种方法:
重新启动shell进程
.或source
例:
. ~/.bashrc
~/.bash_logout退出任务
保存在~/.bash_logout文件中(用户)
在退出登录shell时运行
用于
•创建自动备份
•清除临时文件