
linux用戶的根目錄

Most of the time, none of us willingly performs an action that will literally break our operating systems and force us to reinstall them. But what if such an action could easily occur even by accident on the user’s part? Today’s SuperUser Q&A post has the answer to a confused reader’s question.
在大多數情況下,我們沒人愿意執行會破壞操作系統并強迫我們重新安裝它們的操作。 但是,如果即使是用戶意外,也很容易發生這種動作怎么辦? 今天的“超級用戶問答”帖子回答了一個困惑的讀者的問題。
Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-driven grouping of Q&A web sites.
今天的“問答”環節由SuperUser提供,它是Stack Exchange的一個分支,該社區是由社區驅動的Q&A網站分組。
問題 (The Question)
SuperUser reader fangxing wants to know why Linux would allow users to remove the root directory:
超級用戶閱讀者fangxing想知道為什么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 permissions.
第一次在計算機上安裝Linux時,我總是喜歡使用root,因為不需要每次執行需要root級權限的命令時都添加sudo并輸入密碼。
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.
有一天,我只想刪除一個目錄并運行rm -rf / ,它“破壞了”我的系統。 我一直在想,為什么Linux的設計人員沒有阻止這么危險的命令這么容易地運行。
Why does Linux allow users to remove the root directory?
為什么Linux允許用戶刪除根目錄?
答案 (The Answer)
SuperUser contributor Ben N has the answer for us:
超級用戶貢獻者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).
為什么要阻止您使用自己的計算機執行任何操作? 從根本上登錄或使用sudo對機器說:“我知道我在做什么。” 阻止人們做可疑的事情通常也會阻止他們做聰明的事情(如雷蒙德·陳表示)。
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.
此外,有一個奇特的理由讓用戶可以破壞根目錄:通過完全擦除操作系統和文件系統來停用計算機。 (危險!在某些UEFI系統上, rm -rf /也會使物理機變磚。)在chroot監獄中進行操作也是合理的。
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.
顯然,人們不小心運行了命令,以至于添加了安全功能。 rm -rf /在大多數系統上不執行任何操作,除非還提供了–no-preserve-root ,并且您不可能無意間輸入該內容。 這也有助于防止編寫不良但意圖良好的shell腳本。
Have something to add to the explanation? Sound off in the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.
有什么補充說明嗎? 在評論中聽起來不錯。 是否想從其他精通Stack Exchange的用戶那里獲得更多答案? 在此處查看完整的討論線程。
Image Credit: Wikimedia Commons
圖片來源: Wikimedia Commons
翻譯自: https://www.howtogeek.com/277896/why-does-linux-allow-users-to-remove-the-root-directory/
linux用戶的根目錄