加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – /etc/rc.local和?/ .bashrc有什么区别?

发布时间:2020-12-14 01:38:10 所属栏目:Linux 来源:网络整理
导读:这是一个与 Linux相关的问题.我四处搜寻但没有得到很好的解释. 在我看来,两个文件在我登录时配置设置,但是有什么区别吗?我注意到在确定应该分成两个不同文件的内容时似乎存在“一些规则”.例如,如果我需要为$PATH添加特定的搜索路径,我应该在?/ .bashrc中进
这是一个与 Linux相关的问题.我四处搜寻但没有得到很好的解释.

在我看来,两个文件在我登录时配置设置,但是有什么区别吗?我注意到在确定应该分成两个不同文件的内容时似乎存在“一些规则”.例如,如果我需要为$PATH添加特定的搜索路径,我应该在?/ .bashrc中进行.但是,如果我决定改变一些系统设置,比如

/sys/class/backlight

要么

/sys/devices/cpu/cpu#/online

然后我必须在/etc/rc.local中执行此操作,否则它将无法正常工作.

是因为这些配置在用户之间无法区分吗?

谢谢.

解决方法

不同之处在于它们何时运行以及它们在运行时运行的是谁,即rc.local在运行级别更改时运行并且以root身份运行. bashrc是特定于bash的,并作为特定用户在非登录shell上运行.

你可以在这里找到rc.local的一个很好的解释

The script /etc/rc.local is for use by the system administrator. It is
traditionally executed after all the normal system services are
started,at the end of the process of switching to a multiuser
runlevel. You might use it to start a custom service,for example a
server that’s installed in /usr/local. Most installations don’t need
/etc/rc.local,it’s provided for the minority of cases where it’s
needed.

你可以找到你对bashrc的需求

man bash

When an interactive shell that is not a login shell is started,bash
reads and executes commands from ~/.bashrc,if that
file exists. This may be inhibited by using the –norc option.
The –rcfile file option will force bash to read and
execute commands from file instead of ~/.bashrc.

在这个问题上有关于bashrc的更多信息……

https://superuser.com/questions/49289/what-is-the-bashrc-file

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读