最後更新: 2022-09-21
.bashrc 與 .profile 的分別
.bashrc is a shell script that Bash runs whenever it is started interactively.
.bashrc = bash config file
Bypass .bashrc
--norc # Do not execute initialization file ( /etc/bash.bashrc & ~/.bashrc)
* This option is on by default if the shell is invoked as sh
.bash_profile and .profile which are only run at the start of a new login shell. (bash -l)
Bypass profile
--noprofile
Do not read either the system-wide startup file /etc/profile
any of the personal initialization files ~/.bash_profile, ~/.bash_login, or ~/.profile
載入次序
-
/etc/profile
/etc/bashrc - $HOME/.bash_profile
- $HOME/.bash_login # 未必有
- $HOME/.profile # 未必有
$HOME/.bash_profile
# .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin export PATH
Bash shell is started as a login-shell ?
shopt login_shell
login_shell on
提醒自己是 root (加上了綠色)
在 /root/.bashrc 加上
export PS1='\[\e[32m\]\h:\W\$\[\e[m\]'
- \u – Username
- \h – Hostname (first part)
- \w – Full path of the current working directory
- \W - last part of the current working directory
以免 Del 錯東西
alias rm='rm -i' alias cp='cp -i' alias mv='mv -i'
Centos 7 的 bash_profile
# Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin export PATH
Global Example
# profile for user httpd
/etc/profile.d/httpd.sh
pathmunge /opt/httpd/bin