Linux bashrc和profile的用途和区别

导读 使用终端ssh登陆Linux操做系统的控制台后,会出现一个提示符号(例如:#或~),在这个提示符号以后能够输入命令,Linux根据输入的命令会作回应,这一连串的动做是由一个所谓的Shell来作处理。Shell是一个程序,最经常使用的就是Bash,这也是登陆系统默认会使用的Shell。

Linux bashrc和profile的用途和区别Linux bashrc和profile的用途和区别

• 对于个别用户的启动配置文件linux

用户HOME(家)目录/.bashrcshell

head -1 ~/.bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.

用户HOME(家)目录/.profilebash

head -1 ~/.profile
# ~/.profile: executed by Bourne-compatible login shells.

• 对于所有用户的启动配置文件ssh

head -1 /etc/bash.bashrc
# System-wide .bashrc file for interactive bash(1) shells.

head -2 /etc/profile
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1)
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

• bashrc和profile的差别ide

从上面的英文描述能够知道,bashrc和profile的差别在于:
1. bashrc是在系统启动后就会自动运行。
2. profile是在用户登陆后才会运行。
3. 进行设置后,可运用source bashrc命令更新bashrc,也可运用source profile命令更新profile。
PS:一般咱们修改bashrc,有些linux的发行版本不必定有profile这个文件,本文用的系统是Ubuntu 15.10
4. /etc/profile中设定的变量(全局)的能够做用于任何用户,而~/.bashrc等中设定的变量(局部)只能继承/etc/profile中的变量,他们是"父子"关系。

• 补充介绍操作系统

另外,须要补充说明介绍bashrc相关的几个文件:
~/.bash_profile: 每一个用户均可使用该文件输入专用于本身使用的shell信息,当用户登陆时,该文件仅仅执行一次!默认状况下,他设置一些环境变量,执行用户的.bashrc文件。
~/.bash_logout: 当每次退出系统(退出bash shell)时,执行该文件。
~/.bash_profile 是交互式、login方式进入bash运行的,~/.bashrc是交互式non-login方式进入bash运行的,一般两者设置大体相同,因此一般前者会调用后者。继承

原文来自:http://www.ttlsa.com/linux/linux-bashrc-and-profile/get

相关文章
相关标签/搜索