初识Linux .bash_profile, .bash_logout, and .bashrc 文件
生活随笔
收集整理的這篇文章主要介紹了
初识Linux .bash_profile, .bash_logout, and .bashrc 文件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Linux的.bash_profile, .bash_logout, .bashrc 三個文件對 bash 來說有特殊的意義。你可以通過修改這三個文件讓系統自動為你的賬戶進行個性化環境的設置。這些文件可能存在于你的主目錄下面,如果不存在,那么系統將根據/etc/profile文件進行配置。
.bash_profile非常重要,你每次登錄shell的時候都要去讀這個文件(并且只在登錄時讀取)。查看該文件,可能是如下內容:
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
SHELL=/bin/bash
MANPATH=/usr/man:/usr/X11/man
EDITOR=/usr/bin/vi
PS1='\h:\w\$ '
PS2='> '
export EDITOR
你可以用vi或者emacs對其進行編輯(建議不要更改原來的內容,只要把你要寫的內容添加在后面就行,或者在進行編輯之前對其進行備份)。修改完并不會立即生效,系統必須re-read一下才行。你可以退出并重新登錄系統,或者用source .bash_profile命令使之生效。
.bash_logout相反,每次退出shell的時候才去讀這個文件(并且只在退出時讀取)。如果你需要在退出系統的時候執行一些命令,比如清除一些臨時文件,清除一些日志,你可以把命令寫入該文件。該文件并不是必須存在的,當你發現你的賬號沒有這個文件,那么意味著你退出系統的時候,沒有指定的額外的命令需要執行。
各種版本的shell命名.bash_profile這個文件的方式有所不同。所以當你看到.bash_login,它就對應前文所提的.bash_profile。如果你使用bash登錄,bash首先回去尋找.bash_profile文件,如果該文件不存在,則會自動尋找.bash_login,如果還是不存在,則自動再去尋找 .profile 文件。
.bashrc,The difference between this script and .bashrc is that .bash_profile runs only when you log in. It was originally designed so that you could separate interactive shells from those run by background processors such as cron.But it is not very useful on modern computers with the X Window System because when you open a new terminal window, only .bashrc runs. If you start up a window with the command xterm -ls, it will run .bash_profile too.
.bash_profile非常重要,你每次登錄shell的時候都要去讀這個文件(并且只在登錄時讀取)。查看該文件,可能是如下內容:
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
SHELL=/bin/bash
MANPATH=/usr/man:/usr/X11/man
EDITOR=/usr/bin/vi
PS1='\h:\w\$ '
PS2='> '
export EDITOR
你可以用vi或者emacs對其進行編輯(建議不要更改原來的內容,只要把你要寫的內容添加在后面就行,或者在進行編輯之前對其進行備份)。修改完并不會立即生效,系統必須re-read一下才行。你可以退出并重新登錄系統,或者用source .bash_profile命令使之生效。
.bash_logout相反,每次退出shell的時候才去讀這個文件(并且只在退出時讀取)。如果你需要在退出系統的時候執行一些命令,比如清除一些臨時文件,清除一些日志,你可以把命令寫入該文件。該文件并不是必須存在的,當你發現你的賬號沒有這個文件,那么意味著你退出系統的時候,沒有指定的額外的命令需要執行。
各種版本的shell命名.bash_profile這個文件的方式有所不同。所以當你看到.bash_login,它就對應前文所提的.bash_profile。如果你使用bash登錄,bash首先回去尋找.bash_profile文件,如果該文件不存在,則會自動尋找.bash_login,如果還是不存在,則自動再去尋找 .profile 文件。
.bashrc,The difference between this script and .bashrc is that .bash_profile runs only when you log in. It was originally designed so that you could separate interactive shells from those run by background processors such as cron.But it is not very useful on modern computers with the X Window System because when you open a new terminal window, only .bashrc runs. If you start up a window with the command xterm -ls, it will run .bash_profile too.
轉載于:https://www.cnblogs.com/starspace/archive/2009/02/23/1396250.html
總結
以上是生活随笔為你收集整理的初识Linux .bash_profile, .bash_logout, and .bashrc 文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 第四节(方法一)
- 下一篇: .NET Framework 4.0 和