# 关闭当前终端响铃
setterm -blength 0
# 或者使用
setterm -bfreq 0
xset b off
# 编辑 ~/.bashrc 或 ~/.bash_profile
echo "set bell-style none" >> ~/.inputrc
echo "bind 'set bell-style none'" >> ~/.bashrc
# 或者直接在配置文件中添加
echo "set bell-style none" >> ~/.inputrc
# 编辑全局配置文件
sudo echo "set bell-style none" >> /etc/inputrc
查看对应终端的设置选项,通常可以在"首选项"或"设置"中找到相关选项。
# 关闭当前终端响铃
stty -ixon
# 或者完全禁用
stty -echoctl
在 ~/.bashrc 中添加:
alias belloff='setterm -blength 0; setterm -bfreq 0; echo "Terminal bell disabled"'
alias bellon='setterm -blength 1000; setterm -bfreq 1000; echo "Terminal bell enabled"'
然后重新加载配置:
source ~/.bashrc
编辑 /etc/inputrc 或 ~/.inputrc:
# 禁用响铃
set bell-style none
# 或者设置为可见
# set bell-style visible
执行以下命令测试:
echo -e '\a' # 这会尝试触发响铃
如果设置成功,将不会听到提示音。
source ~/.bashrc
系统范围设置:修改 /etc/inputrc 会影响所有用户
GUI vs CLI:GUI终端和纯命令行终端的设置方式可能不同
优先级:用户级别设置(~/.inputrc)优先于系统级别设置(/etc/inputrc)
推荐使用方法二(修改inputrc文件)作为永久解决方案,因为它兼容性最好且不会影响其他功能。