/etc/rc.local和〜/.bashrc有什么区别? [英] What is the difference between /etc/rc.local and ~/.bashrc?

查看:250
本文介绍了/etc/rc.local和〜/.bashrc有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是与Linux相关的问题.我已经搜索了一下,但没有得到很好的解释.

This is a linux related problem. I have searched around but did not get a good explanation.

在我看来,这两个文件都在我登录时配置了设置,但是有什么区别吗?我注意到在确定应放入两个不同文件中的内容时似乎存在某些规则".例如,如果需要在$ PATH中添加特定的搜索路径,则应在〜/.bashrc中执行.但是,如果我决定更改某些系统设置,例如

It seems to me that both file configure the setup when I log in, but is there any difference? I notice that there seems to be "some rule" in deciding what should go into two different files. For example, if I need to add a specific search path to $PATH, I should do it in ~/.bashrc. But if I decide to change some system setting, like

/sys/class/backlight

/sys/devices/cpu/cpu#/online

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

then I have to do this in /etc/rc.local, otherwise it will not work.

是因为这些配置在用户之间不能相同吗?

Is it because these configurations can not differ between users?

谢谢.

推荐答案

区别在于它们的运行时间,运行的对象以及运行的时间,即rc.local在运行级别更改时运行,并且运行方式为根. bashrc是特定于bash的,并且以特定用户的身份在非登录Shell上运行.

The difference is in when they are run and who they're running as when run i.e. rc.local is run on a change of run level and it runs as root. bashrc is bash specific and run on a non login shell as a particular user.

您可以在此处找到rc.local的很好的解释

You can find a good explanation of rc.local here

脚本/etc/rc.local供系统管理员使用.它是 传统上是在所有正常系统服务都被执行之后执行 开始,在切换到多用户的过程结束时 运行级别.您可以使用它来启动自定义服务,例如 安装在/usr/local中的服务器.大多数安装不需要 /etc/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

启动不是登录shell的交互式shell时,bash 从〜/.bashrc读取并执行命令,如果那样的话 文件已存在.使用--norc选项可以禁止这种情况. --rcfile文件选项将强制bash读取和 从文件而不是〜/.bashrc执行命令.

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的更多信息...

There's more info on bashrc in this question...

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

这篇关于/etc/rc.local和〜/.bashrc有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆