命令行乐趣:嘲讽输错 Bash 命令的用户
创始人
2024-03-01 22:24:48
0

你可以通过配置 sudo 命令去嘲讽输入错误密码的用户。但是现在,当用户在 shell 输错命令时,就能嘲讽他了(滥用?)。

你好 bash-insulter

来自 Github 页面:

当用户键入错误命令,随机嘲讽。它使用了一个 bash4.x. 版本的全新内置错误处理函数,叫 command_not_found_handle

安装

键入下列 git 命令克隆一个仓库:

git clone https://github.com/hkbakke/bash-insulter.git bash-insulter

示例输出:

Cloning into 'bash-insulter'...
remote: Counting objects: 52, done.
remote: Compressing objects: 100% (49/49), done.
remote: Total 52 (delta 12), reused 12 (delta 2), pack-reused 0
Unpacking objects: 100% (52/52), done.

用文本编辑器,比如说使用 vi,编辑你的 ~/.bashrc 或者 /etc/bash.bashrc 文件:

$ vi ~/.bashrc

在其后追加这一行(具体了解请查看 if..else..fi 声明source 命令):

if [ -f $HOME/bash-insulter/src/bash.command-not-found ]; then
    source $HOME/bash-insulter/src/bash.command-not-found
fi

保存并关闭文件。重新登录,如果不想退出账号也可以手动运行它:

$ . $HOME/bash-insulter/src/bash.command-not-found

如何使用它?

尝试键入一些无效命令:

$ ifconfigs
$ dates

示例输出:

一个有趣的 bash 钩子功能,嘲讽输入了错误命令的你。

自定义

你需要编辑 $HOME/bash-insulter/src/bash.command-not-found

$ vi $HOME/bash-insulter/src/bash.command-not-found

示例代码:

command_not_found_handle () {
    local INSULTS=(
        "Boooo!"
        "Don't you know anything?"
        "RTFM!"
        "Hahaha, n00b!"
        "Wow! That was impressively wrong!"
        "What are you doing??"
        "Pathetic"
        "...and this is the best you can do??"
        "The worst one today!"
        "n00b alert!"
        "Your application for reduced salary has been sent!"
        "lol"
        "u suk"
        "lol... plz"
        "plz uninstall"
        "And the Darwin Award goes to.... ${USER}!"
        "ERROR_INCOMPETENT_USER"
        "Incompetence is also competence"
        "Bad."
        "Fake it till you make it!"
        "What is this...? Amateur hour!?"
        "Come on! You can do it!"
        "Nice try."
        "What if... you type an actual command the next time!"
        "What if I told you... it is possible to type valid commands."
        "Y u no speak computer???"
        "This is not Windows"
        "Perhaps you should leave the command line alone..."
        "Please step away from the keyboard!"
        "error code: 1D10T"
        "ACHTUNG! ALLES TURISTEN UND NONTEKNISCHEN LOOKENPEEPERS! DAS KOMPUTERMASCHINE IST NICHT FÜR DER GEFINGERPOKEN UND MITTENGRABEN! ODERWISE IST EASY TO SCHNAPPEN DER SPRINGENWERK, BLOWENFUSEN UND POPPENCORKEN MIT SPITZENSPARKEN. IST NICHT FÜR GEWERKEN BEI DUMMKOPFEN. DER RUBBERNECKEN SIGHTSEEREN KEEPEN DAS COTTONPICKEN HÄNDER IN DAS POCKETS MUSS. ZO RELAXEN UND WATSCHEN DER BLINKENLICHTEN."
        "Pro tip: type a valid command!"
    )

    # 设置“随机”种子发生器 
    RANDOM=$(date +%s%N)
    VALUE=$((${RANDOM}%2))

    if [[ ${VALUE} -lt 1 ]]; then
        printf "\n  $(tput bold)$(tput setaf 1)$(shuf -n 1 -e "${INSULTS[@]}")$(tput sgr0)\n\n"
    fi

    echo "-bash: $1: command not found"

    # 无效命令,常规返回已存在的代码
    return 127
}

赠品:sudo 嘲讽

编辑 sudoers 文件:

$ sudo visudo

追加下面这一行:

Defaults insults

或者像下面尾行增加一句嘲讽语:

Defaults !lecture,tty_tickets,!fqdn,insults

这是我的文件:

Defaults    env_reset
Defaults    mail_badpass
Defaults    secure_path = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
## If set, sudo will insult users when they enter an incorrect password. ##
Defaults    insults

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root ALL = (ALL:ALL) ALL

# Members of the admin group may gain root privileges
% admin ALL = (ALL) ALL   

# Allow members of group sudo to execute any command
% sudo ALL = (ALL:ALL) ALL   

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

试一试:

$ sudo -k # 清除缓存,从头开始
$ sudo ls /root/
$ sudo -i

样例对话:

赠品:你好 sl

sl 或是 UNIX 经典捣蛋软件 游戏。当你错误的把 ls 输入成 sl,将会有一辆蒸汽机车穿过你的屏幕。

$ sl


via: https://www.cyberciti.biz/howto/insult-linux-unix-bash-user-when-typing-wrong-command/

作者:Vivek Gite 译者:CYLeft 校对:wxy

本文由 LCTT 原创编译,Linux中国 荣誉推出

相关内容

伊朗发布AI视频嘲讽特朗普
AIPress.com.cn报道 3月13日消息,在当前中东冲突背...
2026-03-13 19:44:14
开源英雄的窘境:Sudo维...
IT之家 2 月 5 日消息,科技媒体 Linuxiac 昨日(2...
2026-02-05 15:48:18
集特GM0-5603-01...
参数信息 主板:GM0-5603-01 系统:ubuntu-22....
2026-01-27 18:23:35
新买的云服务器如何快速上手...
拿到新云服务器的心情,就像拿到一把新家的钥匙,兴奋之余,可能更多的...
2026-01-26 10:17:31
Linux祖师爷真香现场!...
新智元报道 编辑:定慧 【新智元导读】Linux之父「叛变」了!...
2026-01-12 20:18:39
贝索斯创办AI初创公司,马...
IT之家 11 月 18 日消息,据《纽约时报》昨日报道,亚马逊创...
2025-11-18 07:45:10

热门资讯

PHP最佳实践(译) 简介PHP是一门复杂的语言,经过多年折腾,使其不同版本之间高度不一致,有时还有些bug。 每个版本都...
值得收藏的 27 个机器学习的... 机器学习 ( Machine Learning ) 有很多方面,当我开始研究学习它时,我发现了各种各...
8 个提升你的隐私防护的开源密... 使用一些顶级开源密码管理器,确保你的登录凭证安全无虞。密码管理器是一项非常有用的实用程序。在你想寻找...
硬核观察 #885 苹果 AR... 苹果 AR 眼镜被无限期推迟据报道,由于技术上的挑战,苹果公司已经无限期推迟了其轻型增强现实(AR)...
为什么计量 IT 的生产力如此... 在某些行业里,人们可以根据一些测量标准判定一个人的生产力。比如,如果你是一个零件制造商,可以通过一个...
8个有趣的Linux提示与技巧... 我们时不时给你带来关于Linux的提示与技巧。和这个系列保持一致,这里有8个我们从读者收到最有趣的提...
Helix:高级 Linux ... 说到 基于终端的文本编辑器,通常 Vim、Emacs 和 Nano 受到了关注。这并不意味着没有其他...
2020 年的 GitHub ... 距离 2020 年结束只剩下区区 24 天,我们即将结束魔幻的 2020 ,迎来新的一年,新的一年或...
开源新闻速递:openSUSE... 今日关注openSUSE 项目组的 Dominique Leuenberger 在他的周报中说:“这...
KDE4.11 Beta1 正...   KDE 项目工作组刚刚发布了 KDE Software Compilation 4.11 Bet...