为什么linux允许用户删除根目录?

大多数时候,我们中没有人愿意执行一个会破坏我们的操作系统并迫使我们重新安装它们的操作。但是,如果这样的行为很容易发生,即使是用户的意外呢?今天的超级用户问答帖子回答了一个困惑读者的问题。...

为什么linux允许用户删除根目录?

大多数时候,我们中没有人愿意执行一个会破坏我们的操作系统并迫使我们重新安装它们的操作。但是,如果这样的行为很容易发生,即使是用户的意外呢?今天的超级用户问答帖子回答了一个困惑读者的问题。

今天的问答环节是由SuperUser提供的,SuperUser是Stack Exchange的一个分支,是一个由社区驱动的问答网站分组。

问题

超级用户读者方兴想知道为什么Linux允许用户删除根目录:

When I installed Linux on my computer for the first time, I always liked to use root because I did not need to add sudo and enter my password every time I executed a command that needed root level permissi***.

One day, I just wanted to remove a directory and ran rm -rf  /, which “broke” my system. I have been wondering why Linux’s designers did not block such a dangerous command from being run so easily.

为什么Linux允许用户删除根目录?

答案

超级用户贡献者Ben N为我们提供了答案:

Why should it block you from doing whatever you want with your own computer? Logging in as root or using sudo is literally saying to the machine, “I know what I am doing.” Preventing people from doing dubious things usually also prevents them from doing clever things (as expressed by Raymond Chen).

Besides, there is one singularly good reason to allow a user to torch the root directory: decommissioning a computer by completely erasing the operating system and file system. (Danger! On some UEFI systems, rm -rf / can brick the physical machine too.) It is also a reasonable thing to do inside a chroot jail.

Apparently, people accidentally ran the command so much that a safety feature was added. rm -rf / does nothing on most systems unless –no-preserve-root is also supplied, and there is no way that you can type that by accident. That also helps guard against poorly-written but well-intentioned shell scripts.


有什么要补充的解释吗?在评论中发出声音。想从其他精通技术的Stack Exchange用户那里了解更多答案吗?在这里查看完整的讨论主题。

图片来源:Wikimedia Comm***

  • 发表于 2021-04-08 21:37
  • 阅读 ( 109 )
  • 分类:互联网

你可能感兴趣的文章

使用以下技巧和技巧成为linux命令行高手

... 除了切换文件夹外,命令行还允许创建文件夹。可以通过运行以下命令创建目录: ...

  • 发布于 2021-03-12 10:19
  • 阅读 ( 276 )

Windows10中LinuxBashShell快速指南

...性。了解更多关于Bash-on-Windows的信息,从您应该如何以及为什么安装它,到您可能不知道的隐藏特性。 ...

  • 发布于 2021-03-17 01:06
  • 阅读 ( 194 )

linux命令参考备忘单

...对于长期用户,也有太多的命令要提交到内存中。这就是为什么我们准备了这个方便的Linux命令备忘单。如果您想运行其中的几个,请查看如何在带屏幕的Linux终端上执行多任务。 ...

  • 发布于 2021-03-22 04:06
  • 阅读 ( 233 )

解释了chmod命令和linux文件权限

...行(x)权限(按所有者、组和其他人的顺序)。如果不允许,则使用破折号(-)。 ...

  • 发布于 2021-03-25 12:15
  • 阅读 ( 171 )

如何在linux中添加用户

...多数人第一次在电脑上使用Linux时都会感到困惑。这就是为什么如果您要从任何其他操作系统切换到Linux,选择正确的发行版是很重要的。 ...

  • 发布于 2021-03-26 23:29
  • 阅读 ( 334 )

如何在arch linux中安装和删除软件包

...安装其他包管理器,比如Yay。与Pacman不同,这些包管理器允许您从官方的Arch存储库和AUR(Arch用户存储库)添加新包。 ...

  • 发布于 2021-03-28 02:18
  • 阅读 ( 463 )

终极树莓皮命令备忘单

... 这就是为什么我们准备了这个方便的备忘单的日常使用树莓皮。 ...

  • 发布于 2021-03-30 18:59
  • 阅读 ( 245 )

如何用testdisk恢复linux上删除的文件

...到了无法挽回的失落,这是你永远都会感激的。 这就是为什么testdisk是如此方便的实用工具。当你通过菜单,可以开始恢复文件,很容易陷入一个节奏的突出显示,c,c,重复。

  • 发布于 2021-04-01 08:34
  • 阅读 ( 313 )

linux下如何使用pushd和popd

...后,您将有一种在目录之间跳转的超快速方法。 这就是为什么我们要挂在命令行上。效率很高,对吧? 相关:您应该知道的37条重要的Linux命令

  • 发布于 2021-04-02 13:29
  • 阅读 ( 138 )

如何在linux上使用suid、sgid和sticky位

...念,我们创建了一个名为htg的小程序。它位于dave用户的根目录中,并且没有SUID位。当它被执行时,它显示真实有效的用户id(UID)。 真正的UID属于启动程序的人。有效ID是程序运行时所使用的帐户,就像启动程序时所使用的帐...

  • 发布于 2021-04-02 14:48
  • 阅读 ( 173 )
YuXiaooz
YuXiaooz

0 篇文章

相关推荐