修改 /etc/profile 的修改技巧
在 Arch Linux 的配置过程中可能要修改 /etc/profile,修改多了以后,原来的 profile 就面目全非了。
仔细看看你的 Linux 系统,如果有 /etc/profile.d 目录的话,就可以把要修改的内容分文件存放。
使 ls 能带颜色显示目录
建立文件 /etc/profile.d/dircolor.sh,内容如下:
# Setup for /bin/ls to support color, the alias is in /etc/bashrc.
if [ -f "/etc/dircolors" ] ; then
eval $(dircolors -b /etc/dircolors)
if [ -f "$HOME/.dircolors" ] ; then
eval $(dircolors -b $HOME/.dircolors)
fi
fi
alias ls='ls --color=auto'
修改 dircolor.sh 为可执行模式
# cd /etc/profile.d
# chmod +x dircolor.sh
修改完毕后,重新登录,使修改内容生效。
在 path 中增加新的目录
建立文件 /etc/profile.d/addsbin.sh,内容如下:
# Functions to help us manage paths. Second argument is the name of the
# path variable to be modified (default: PATH)
pathremove () {
local IFS=':'
local NEWPATH
local DIR
local PATHVARIABLE=${2:-PATH}
for DIR in ${!PATHVARIABLE} ; do
if [ "$DIR" != "$1" ] ; then
NEWPATH=${NEWPATH:+$NEWPATH:}$DIR
fi
done
export $PATHVARIABLE="$NEWPATH"
}
pathprepend () {
pathremove $1 $2
local PATHVARIABLE=${2:-PATH}
export $PATHVARIABLE="$1${!PATHVARIABLE:+:${!PATHVARIABLE}}"
}
pathappend () {
pathremove $1 $2
local PATHVARIABLE=${2:-PATH}
export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1"
}
if [ $EUID -eq 0 ] ; then
pathappend /sbin
pathappend /usr/sbin
pathappend /usr/local/sbin
unset HISTFILE
fi
pathappend /usr/local/bin
修改 addsbin.sh 为可执行模式
# cd /etc/profile.d
# chmod +x addsbin.sh
修改完毕后,重新登录,使修改内容生效。
修改 Prompt
建立文件 /etc/profile.d/prompt.sh,内容如下:
# Setup a red prompt for root and a green one for users.
NORMAL="\[\e[0m\]"
RED="\[\e[1;31m\]"
GREEN="\[\e[1;32m\]"
if [[ $EUID == 0 ]] ; then
PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL"
else
PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
fi
修改 prompt.sh 为可执行模式
# cd /etc/profile.d
# chmod +x prompt.sh
修改完毕后,重新登录,使修改内容生效。
作用原理
这些文件能够发生作用,取决于 /etc/profile 的以下内容:
# Load profiles from /etc/profile.d
if test -d /etc/profile.d/; then
for profile in /etc/profile.d/*.sh; do
test -x $profile && . $profile
done
unset profile
fi
仔细看看你的 Linux 系统,如果有 /etc/profile.d 目录的话,就可以把要修改的内容分文件存放。
使 ls 能带颜色显示目录
建立文件 /etc/profile.d/dircolor.sh,内容如下:
# Setup for /bin/ls to support color, the alias is in /etc/bashrc.
if [ -f "/etc/dircolors" ] ; then
fi
alias ls='ls --color=auto'
修改 dircolor.sh 为可执行模式
# cd /etc/profile.d
# chmod +x dircolor.sh
修改完毕后,重新登录,使修改内容生效。
在 path 中增加新的目录
建立文件 /etc/profile.d/addsbin.sh,内容如下:
# Functions to help us manage paths.
# path variable to be modified (default: PATH)
pathremove () {
}
pathprepend () {
}
pathappend () {
}
if [ $EUID -eq 0 ] ; then
fi
pathappend /usr/local/bin
修改 addsbin.sh 为可执行模式
# cd /etc/profile.d
# chmod +x addsbin.sh
修改完毕后,重新登录,使修改内容生效。
修改 Prompt
建立文件 /etc/profile.d/prompt.sh,内容如下:
# Setup a red prompt for root and a green one for users.
NORMAL="\[\e[0m\]"
RED="\[\e[1;31m\]"
GREEN="\[\e[1;32m\]"
if [[ $EUID == 0 ]] ; then
else
fi
修改 prompt.sh 为可执行模式
# cd /etc/profile.d
# chmod +x prompt.sh
修改完毕后,重新登录,使修改内容生效。
作用原理
这些文件能够发生作用,取决于 /etc/profile 的以下内容:
# Load profiles from /etc/profile.d
if test -d /etc/profile.d/; then
fi