手动添加
vim ~/.bashrc
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
脚本添加
注:对于centos7以及debian9亲测可行,其他未实践
以下为添加脚本,新建一个1.sh,赋予执行权限,chmod +x 1.sh,添加以下内容,运行即可,./1.sh
需要什么就在alias后面改就是了
touch /etc/profile.d/my_alias.sh
cd /etc/profile.d
cat>>my_alias.sh<<EOF
alias se='setenforce'
alias ge='getenforce'
alias g='systemctl stop firewalld'
alias e='systemctl enable'
alias s='systemctl start'
alias re='systemctl restart'
alias st='systemctl stop '
alias yu='yum install -y '
alias qa='rpm -qa|grep '
alias net='netstat -lanp|grep '
alias ta='systemctl status '
EOF
source my_alias.sh
if [ $? -eq 0 ]
then
echo success
echo diretory /etc/profile.d
echo file my_alias.sh
fi
注:运行上述脚本后,新打开的命令窗口即可使用简化过的命令,如果是执行该脚本的窗口需要到/etc/profile.d目录下,执行source my_alias.sh即可