Linux bashrc和profile的用途和区别

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

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

用户HOME(家)目录/.bashrc

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

用户HOME(家)目录/.profile

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

• 对于全部用户的启动配置文件

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的差异

从上面的英文描述可以知道,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.linuxprobe.com/linux-bashrc-profile-different.html

更多Linux干货请访问:http://www.linuxprobe.com/

时间: 2024-08-04 01:54:36

Linux bashrc和profile的用途和区别的相关文章

【转】Linux中/etc/profile,/etc/bashrc,~/.profile,~/.bashrcd的区别

//因为在原文章中博主说以下内容是网友说的,所以我就只加个转了,找不到原作者 /etc/profile,/etc/bashrc 是系统全局环境变量设定 ~/.profile,~/.bashrc用户家目录下的私有环境变量设定 当登入系统时候获得一个shell进程时,其读取环境设定档有三步 1首先读入的是全局环境变量设定档/etc/profile,然后根据其内容读取额外的设定的文档,如 /etc/profile.d和/etc/inputrc 2然后根据不同使用者帐号,去其家目录读取~/.bash_p

linux bashrc /etc/profile ./profile ./bashrc linux 用户配置文件启动顺序

转:http://www.cnblogs.com/hongzg1982/articles/2101792.html bashrc与profile的区别 要搞清bashrc与profile的区别,首先要弄明白什么是交互式shell和非交互式shell,什么是login shell 和non-login shell. 交互式模式就是shell等待你的输入,并且执行你提交的命令.这种模式被称作交互式是因为shell与用户进行交互.这种模式也是大多数用户非常熟悉的:登录.执行一些命令.签退.当你签退后,

linux关于bashrc与profile的区别(转)

bashrc与profile的区别 要搞清bashrc与profile的区别,首先要弄明白什么是交互式shell和非交互式shell,什么是login shell 和non-login shell. 交互式模式就是shell等待你的输入,并且执行你提交的命令.这种模式被称作交互式是因为shell与用户进行交互.这种模式也是大多数用户非常熟悉的:登录.执行一些命令.签退.当你签退后,shell也终止了. shell也可以运行在另外一种模式:非交互式模式.在这种模式下,shell不与你进行交互,而是

linux 下/etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc 文件的区别

/etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行. 并从/etc/profile.d目录的配置文件中搜集shell的设置. /etc/bashrc:为每一个运行bash shell的用户执行此文件.当bash shell被打开时,该文件被读取. ~/.bash_profile:每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登录时,该 文件仅仅执行一次!默认情况下,他设置一些环境变量,执行用户的.bashrc文件. ~/.bashrc

[转] - bashrc与profile的区别

bashrc与profile的区别 要搞清bashrc与profile的区别,首先要弄明白什么是交互式shell和非交互式shell,什么是login shell 和non-login shell. 交 互式模式就是shell等待你的输入,并且执行你提交的命令.这种模式被称作交互式是因为shell与用户进行交互.这种模式也是大多数用户非常熟悉的: 登录.执行一些命令.签退.当你签退后,shell也终止了. shell也可以运行在另外一种模式:非交互式模式.在这种模式下,shell不与你进行交互,

理解 bashrc 和 profile(转)

转自:https://wido.me/sunteya/understand-bashrc-and-profile/ 在一般的 linux 或者 unix 系统中, 都可以通过编辑 bashrc 和 profile 来设置用户的工作环境, 很多文章对于 profile 和 bashrc 也都有使用, 但究竟每个文件都有什么作用和该如何使用呢? 首先我们来看系统中的这些文件, 一般的系统可能会有 1 2 3 4 5 /etc/profile /etc/bashrc ~/.bashrc ~/.prof

bashrc与profile的相关知识

bashrc与profile的共同点:         都可存储环境变量. bashrc与profile的区别: bashrc-->非交互式:在这种模式下,shell不与你进行交互,而是读取存放在文件中的命令,并且执行它们.当它读到文件的结尾,shell也就终止了. profile:-->交互式:交互式模式就是shell等待你的输入,并且执行你提交的命令. 其他相关介绍: /etc/profile,/etc/bashrc 是系统全局环境变量设定 ~/.profile,~/.bashrc用户家目

Linux /bin, /sbin, /usr/bin, /usr/sbin 区别(转)

在linux下我们经常用到的四个应用程序的目录是:/bin./sbin./usr/bin./usr/sbin bin:  bin为binary的简写主要放置一些系统的必备执行档例如:cat.cp.chmod df.dmesg.gzip.kill.ls.mkdir.more.mount.rm.su.tar等. /usr/bin: 主要放置一些应用软件工具的必备执行档例如c++.g++.gcc.chdrv.diff.dig.du.eject.elm.free.gnome*. zip.htpasswd

Linux /bin /sbin /usr/bin /usr/sbin 区别

分享一下我老师大神的人工智能教程吧.零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!http://www.captainbed.net 在linux下我们经常用到的四个应用程序的目录是:/bin./sbin./usr/bin./usr/sbin bin:  bin为binary的简写主要放置一些系统的必备执行档例如:cat.cp.chmod df.dmesg.gzip.kill.ls.mkdir.more.mount.rm.su.tar等. /usr/bin: 主要