环境变量

登录的环境变量配置文件

  1. /etc/profile(所有用户生效)
  2. /etc/profile.d/*.sh
  3. ~/.bash_profile
  4. ~/.bashrc(当前用户生效)
  5. /etc/bashrc

配置文件生效

. 文件

source 文件

配置文件生效过程

Alt environment

/etc/profile

  1. if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then
  2. umask 002
  3. else
  4. umask 022
  5. fi
  6. ...
  7. for i in /etc/profile.d/*.sh ; do
  8. if [ -r "$i" ]; then
  9. if [ "${-#*i}" != "$-" ]; then
  10. . "$i"
  11. else
  12. . "$i" >/dev/null 2>&1
  13. fi
  14. fi
  15. done
  16. [root@localhost ~]# umask
  17. 0022

umask查看系统默认权限

文件最高权限666

目录最高权限777

权限不能用数字换算,必须用字母

umask定义的权限,是系统权限中准备丢弃的权限

  1. rw-rw-rw- ----w--w- r--r--r--
  2. rwxrwxrwx ----w--w- rwxr-xr-x755

环境变量配置文件的功能

1.USER变量

2.LOGNAME变量

3.MAIL变量

4.PATH变量

5.HOSTNAME变量

6.HISTSIZE变量

7.umask

8.调用/etc/profile.d/*.sh

  1. ~/.bash_profile
  2. if [ -f ~/.bashrc ]; then
  3. . ~/.bashrc
  4. fi

变量叠加,重新生效 重复定义的变量,后面的配置覆盖前面的

  1. ~/.bashrc(定义别名)
  2. # Source global definitions
  3. if [ -f /etc/bashrc ]; then
  4. . /etc/bashrc
  5. fi

/etc/bashrc

  1. PS1变量(起始符)
  2. umask
  3. PASH变量

其他环境变量配置文件

注销时生效的环境变量配置文件

  1. ~/.bash_logout

(比用命令看少,保存在内存中,退出后记录)

  1. ~/.bash_history

shell登录信息

登录前欢迎信息

本地终端登录信息

  1. /etc/issue

远程终端登录信息

  1. /etc/issue.net

需要配置

  1. /etc/ssh/sshd_config
  2. Banner /etc/issue.net

登录后欢迎信息(包括本地和远程)

  1. /etc/motd
linux7