Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between /etc/rc.local and ~/.bashrc?

Tags:

linux

ubuntu

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

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

or

/sys/devices/cpu/cpu#/online

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?

Thanks.

like image 801
Zheyuan Li Avatar asked Apr 02 '16 16:04

Zheyuan Li


People also ask

What is a ~/ bashrc file?

The . bashrc file is a script file that's executed when a user logs in. The file itself contains a series of configurations for the terminal session. This includes setting up or enabling: coloring, completion, shell history, command aliases, and more. It is a hidden file and simple ls command won't show the file.

What does etc RC local do?

/etc/rc. local is almost the last script called at boot up. This script can be edited by the administrator to start local daemons that don't fit the rc.

What does RC in bashrc mean?

Run commands/control. The term rc stands for the phrase "run commands". It is used for any file that contains startup information for a command. It is believed to have originated somewhere in 1965 from a runcom facility from the MIT Compatible Time-Sharing System (CTSS). and.

What is the difference between ETC profile and etc bashrc?

The difference is simple, the /etc/profile is executed only for interactive shells and the /etc/bashrc is executed for both interactive and non-interactive shells.


1 Answers

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.

You can find a good explanation of rc.local here

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.

and you can find what you need about 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.

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

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

like image 80
Harry Avatar answered Oct 27 '22 22:10

Harry