有时候不知什么原因,自己的 Ubuntu 系统或者刚重装的 VPS 没有开启自动补全, 在命令行下的输入效率便降低了很多很多,这里就告诉大家如何开启。

出现这种情况的原因之一很有可能是自动补全组件没有安装,在命令行输入:

$ apt install bash-completion

然后修改 .bashrc

$ vim ~/.bashrc

在文件末尾找到:

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
#if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
#    . /etc/bash_completion
#fi

将后三行的注释取消掉:

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi

再执行 source .bashrc 或者重启系统,就可以愉快地使用自动补全啦!