1、别名配置文件为 ~/.bashrc.

例如将:为‘echo $?’命令指定别名为q:

[root@centos79 ~]# vim ~/.bashrc
# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias q='echo $?'   ## 增加该行

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

 

2、测试效果

[root@centos79 ~]# q
bash: q: command not found...
[root@centos79 ~]# source ~/.bashrc   ## 重新加载配置文件
[root@centos79 ~]# q 
0
[root@centos79 ~]# mkdir Music/
mkdir: cannot create directory ‘Music/’: File exists
[root@centos79 ~]# q
1