解决办法(以Centos 9 Stream为例):
如果您在CentOS 9上无法自动补全命令,您可以尝试以下步骤:
- 检查bash-completion软件包是否已安装。如果未安装,请使用以下命令安装:
sudo dnf install bash-completion
- 确保您的.bashrc文件中包含以下行(如果没有就复制粘贴进去):
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
修改完之后的.bashrc内容:
[root@M001 ~]# cat .bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific environment
if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]
then
PATH="$HOME/.local/bin:$HOME/bin:$PATH"
fi
export PATH
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
############################就像这样############################
# Command auto completion --xiamingliang
# The prerequisite is to install the bash-completion
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
###############################################################
[root@M001 ~]#
3. 使用以下命令将其添加到.bashrc文件中:
source ~/.bashrc
如果您仍然无法自动补全命令,尝试重启计算机并重新尝试上述步骤。