这个命令 :(){ :|: & };: 有什么作用?

man*_*m-n 3 linux bash shell shell-script denial-of-service

这个 shell 命令在 Linux 中有什么作用

:(){ :|: & };:
Run Code Online (Sandbox Code Playgroud)

它如何用于拒绝服务攻击?

Ric*_*lka 6

这是一个叉子炸弹。当我说话时,我实际上已经把它写在我的白板上(作为一个笑话)。不要运行它。

:()         # define a function named :, () defines a function in bash
{           
    : | :;  # the pipe needs two instances of this function, which forks two shells
}
;           # end function definition
:           # run it
Run Code Online (Sandbox Code Playgroud)

因此,第一次运行会生成 2 个子外壳,然后每个子外壳再运行 2 个子外壳......

: 是 bash 中的内置命令。这是一种“空”无操作命令。在有注释字符之前,它曾经是注释字符。现在,它作为无操作的用途很小,但在这里真正使用,因为它更神秘,你看着:()并认为是 WTH 吗?