ubuntu /etc/profile配置

修改 /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
这段命令的作用是: 1. 执行 `source /etc/profile` 命令,使得之前添加的 Go 语言环境变量生效; 2. 执行 `mkdir -p /home/ubuntu/gopath/src/github.com/hyperledger` 命令,创建一个目录用于存放 Hyperledger Fabric 的源代码; 3. 执行 `cd /home/ubuntu/gopath/src/github.com/hyperledger` 命令,切换到 Hyperledger Fabric 代码存放的目录; 4. 执行 `cp /resource/docker-compose /usr/local/bin` 命令,将预设好的 `docker-compose` 文件拷贝到 `/usr/local/bin` 目录下; 5. 执行 `chmod +x /usr/local/bin/docker-compose` 命令,添加可执行权限; 6. 执行 `cp /resource/fabric-samples.tar.gz /home/ubuntu/gopath/src/github.com/hyperledger` 命令,将预设好的 Hyperledger Fabric 样例程序压缩包拷贝到 `github.com/hyperledger` 目录下; 7. 执行 `cd /home/ubuntu/gopath/src/github.com/hyperledger` 命令,切换到 Hyperledger Fabric 样例程序所在的目录; 8. 执行 `tar -xf ./fabric-samples.tar.gz` 命令,解压 Hyperledger Fabric 样例程序压缩包; 9. 执行 `source /etc/profile` 命令,重新加载 Go 语言环境变量; 10. 执行 `cd /home/ubuntu/gopath/src/github.com/hyperledger/fabric-samples/scripts` 命令,切换到 Hyperledger Fabric 样例程序的脚本目录; 11. 执行 `./bootstrap.sh 1.4.0 1.4.0 0.4.14` 命令,安装 Hyperledger Fabric 所需的依赖组件; 12. 执行 `cd /home/ubuntu/gopath/src/github.com/hyperledger/fabric-samples/first-network` 命令,切换到 Hyperledger Fabric 样例程序的第一个网络目录; 13. 执行 `./byfn.sh up -s couchdb` 命令,启动第一个网络,并使用 CouchDB 作为状态数据库; 14. 执行 `docker-compose -f docker-compose-cli.yaml -f docker-compose-couch.yaml -f docker-compose-kafka.yaml start` 命令,启动 Fabric 网络中的 Docker 容器; 15. 执行 `../bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx channel-artifacts/test.tx -channelID test` 命令,使用 configtxgen 工具生成通道交易配置文件和创世块配置文件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值