Differences between. bash_pfofile,. bash_logout and. bashrc in Linux

Source: Internet
Author: User
In Linux,. bash_profile,. bash_logout, and. bashrc files have special meanings for bash. When a user logs on or calls another bashshell, they provide a method to automatically establish the logon account environment and allow various commands to be executed when the user exits. I have never understood the relationship between. bash_profile and. bashrc. In today's Linux environment,. bash_profile,. bash_logout, and. bashrc files have special meanings for bash. They log on to the user or call another bash
Shell provides a way to automatically create the login account environment and allow various commands to be executed when exiting. I have never understood the relationship between. bash_profile and. bashrc. I took the time to read the book and record it.
First, some brothers may say that they do not have these files in their home directories. What is the initial environment used? If these files do not exist, log on to the default system file/etc/profile. check whether the file exists.

. Bash_profile file
. Bash_profile is the most important file. This file is read every time you log on to the system, and the commands contained in it are executed by bash.
This file defines the basic environment of the user's logon account, including the PATH of the PATH and some alias settings.
If you change the content of your. bash_profile file, the change will not take effect until you log out and log on again, and the file is read again. If your temper is urgent, use source. bash_profile to make the change take effect immediately.
My personal. bash_profile file configuration is as follows:
PS1 = '$ {debian_chroot: + ($ debian_chroot)} \ [\ 033 [01; 32m \] \ u @ \ h \ [\ 033 [00m \]: \ [\ 033 [01; 34m \] \ w \ [\ 033 [00m \] \ $'
# PS1 = '$ {debian_chroot: + ($ debian_chroot)} \ u @ \ h: \ w \ $'
PS1 = "\ [\ e] 0; $ {debian_chroot: + ($ debian_chroot)} \ u @ \ h: \ w \ a \] $ PS1"
Export PS1
Export PAGER = less
Export BLOCKSIZE = K
Export HISTFILE = ~ /. Bash_history
Export RSYNC_RSH = ssh
Export PHPADMIN_HOME = $ HOME/htdocs/phpMyAdmin
Export OAUTH_HOME = $ HOME/htdocs/oauthalias ls = 'ls -- color = auto'
Alias ll = 'ls-lGA'
Alias vdiff = 'vim + "DirDiff "'
Alias grep = 'grep -- color = auto'
Alias fgrep = 'fgrep -- color = auto'
Alias egrep = 'egrep -- color = auto'
Alias rm = 'rm-I'
Alias mv = 'MV-I'
Alias cp = 'CP-I'
Alias sco = 'svn Co'
Alias sci = 'svn ci-m ""'
Alias sup = 'svn up'
Alias st = "svn st"
Alias kg = 'qpkg info'
Alias aconf = 'pushd.; cd/usr/local/apache2/conf/include'
Alias alog = 'pushd.; cd/usr/local/apache2/logs'
Alias abin = 'pushd.; cd/usr/local/apache2/bin'
Alias bk = 'popd'
Alias his = 'History'
Alias hisgrep = 'History | grep'

. Bashrc file
As described above. bash_profile, what does. bashrc do?
The. bash_profile file is read and executed only by the login shell, that is, if your initial shell is cshell. When you execute bash to switch to the bash environment, it does not read. bash_profile. The. bashrc file is read.

. Bash_logout file

I have made the least changes to this file because it is almost useless.
The. bash_logout file is read and executed every time the logon shell exits.
This file provides the ability to customize the user environment. That is, if you execute commands such as deleting temporary files in an account or recording the time spent on logging on to the system, you can place these commands in. bash_logtou.
If the file does not exist, no other commands will be executed when you exit.

Summary
To put it bluntly, the three files can be simply summarized as follows:
. Bash_profile is similar to the constructor in programming. when you log on to shell, shell will look for this file for environment initialization.
. Bashrc is a substitute for. bash_profile.
. Bash_logout is similar to the Destructor in programming. when the login shell exits, the shell will look for the file and follow the instructions.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.