Solved

Linux, .bashrc

Posted on 2012-04-02
5
562 Views
Last Modified: 2012-04-03
What is the purpose of the .bashrc file as oposed to the .profile file
0
Comment
Question by:Los Angeles1
5 Comments
 
LVL 15

Assisted Solution

by:mish33
mish33 earned 100 total points
Comment Utility
.profile runs when you log in
.bashrc run on every new terminal window
0
 
LVL 31

Assisted Solution

by:farzanj
farzanj earned 100 total points
Comment Utility
.profile is typically for login shell.  So it is triggered when you logon.
.bash.rc is triggered every time a subshell is spawned.
0
 
LVL 26

Assisted Solution

by:pony10us
pony10us earned 100 total points
Comment Utility
I think this:  http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html  might give you a good starting point to understanding the difference.

Basically the bash_profile runs like a windows login script (only at login) as opposed to bashrc runs in the background as a process monitoring everything continously.

That is a very basic explanation and is detailed better at the link above.
0
 
LVL 11

Assisted Solution

by:legolasthehansy
legolasthehansy earned 100 total points
Comment Utility
THe .bashrc file is your start up file when you login. Your aliases can be defined here so that you can run them while you are on shell.
eg. - alias rm='rm -i'

Do a cat ~/.bashrc to see it

The .profile file is for non-bash shells to load environment variables.
0
 
LVL 1

Accepted Solution

by:
Faher earned 100 total points
Comment Utility
When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.
...
When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if these files exist. 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 /etc/bash.bashrc and ~/.bashrc.

As far as I understand, a login shell means a session where you log in to the system and directly end up in Bash, like a remote ssh session or logging in through a non-graphical text terminal. A non-login shell is then the type of shells you open after logging in: typically in a graphical session when you open a new terminal window.

How I think things are supposed to work (for a typical setup):

.profile is for things that are not specifically related to Bash, like environment variables PATH and friends, and should be available anytime. For example, .profile should also be loaded when starting a graphical desktop session.

.bashrc is for the configuring the interactive Bash usage, like Bash aliases, setting your favorite editor, setting the Bash prompt, etc.

As stated in the man page excerpt above, if you would omit .bash_profile, only .profile would be loaded.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

In this tutorial I will explain how to make squid prevent malwares in five easy steps: Squid is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-…
Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now