Merge pull request #5889 from firmianay/master

[translating by firmianay]20170711 The Filesystem Hierarchy Standard Shows Which Bits Are Boss.md
This commit is contained in:
Xingyu.Wang 2017-08-04 16:13:18 +08:00 committed by GitHub
commit fe0e07187c
2 changed files with 91 additions and 99 deletions

View File

@ -1,99 +0,0 @@
The Filesystem Hierarchy Standard Shows Which Bits Are Boss
============================================================
![linux](http://www.linuxinsider.com/article_images/story_graphics_xlarge/xl-2016-linux-1.jpg)
[**The State of Open Source Software: Year in Review | Webinar**][5]
[][6]Flexera Software's VP of Product Management discusses the compliance and vulnerability events and trends from 2016 impacting organizations using open source software. 
**[Watch Now!][3]**
If you've ever been curious enough to look through your system's root directory ("/"), you may have found yourself a little overwhelmed. Most of the three-letter directory names don't tell you much about what they do, and if you ever needed to make important modifications, it would be tough to know where to look.
I'd like to take those of you who haven't ventured much into your root directory on a brief tour.
### Helpful Tools
Before we embark, here are a couple of tools that are worth getting familiar with, as they will allow you to dig through anything interesting you find on your own later. None of these programs will make any changes to your files.
The most useful tool is "ls" -- it lists the contents of any directory given with a full or relative path (i.e., one starting from the current directory) as an argument.
$ ls  _path_
As you progress deeper into the filesystem, it might get cumbersome to type long paths repeatedly, so if you get to that point, you can replace "ls" with "cd" to change the current working directory (the one your terminal is currently "in") to that directory. As with "ls", just give "cd" a directory path as an argument.
$ cd  _path_
If you're not sure what kind of file something is, use the "file" command on it by running "file" and the filename as an argument.
$ file  _filename_
Finally, if the file seems like it could be human-readable, use "less" to look at it (again, with no fear of making changes). As with the last tool, give a filename as an argument to view it.
$ less  _filename_
When you're done scanning through the file, hit "q" to quit, which returns you to your terminal.
### Root Directory Road Trip
Now we can begin our journey. I'm going to proceed in alphabetical order through the directories directly within the root directory. This is by no means an exhaustive catalog, but by the end, we will have hit the highlights.
All of the classifications and functions of the directories we will go over are based on the Linux Filesystem Hierarchy Standard, or FHS. The Linux FHS, maintained by the [Linux Foundation][4], assists designers and developers of distributions and programs by structuring where the various components of their tools should go.
By keeping all of the files, binaries, and manuals in a consistent organization across programs, the FHS makes learning, debugging, or modifying them much easier. Imagine how tedious it would be if instead of using the "man" command to find usage guides, you had to hunt for the manual for every program.
Alphabetically, and structurally, it is fitting that we start with **"/bin"**. This directory is where all the core system binary files containing commands for the shell (the program that interprets terminal instructions) are found. Without the contents of this directory, your system wouldn't do much.
Next is the **"/boot"** directory, where all the stuff your computer needs to boot up is stored. Among these things, the most important ones are your bootloader and kernel. The bootloader is the program that initializes a few basic utilities to allow the boot process to continue. At the end of its initialization, the bootloader loads the kernel, which allows the computer to interface with all other hardware and firmware. From this point, it can proceed to bring the entire operating system online.
The **"/dev"** directory is where file-like objects representing everything your system recognizes as a "device" are stored. These includes obvious devices such as the hardware components of your computer: your keyboard, screen, hard drive, etc.
Additionally, "/dev" contains pseudo-files signifying streams of data that your system treats as "devices." One example is the data that goes in and out of your terminal, which is divided into three "streams." Information it reads coming in is called "standard input." The output of commands or processes is "standard output." Finally, an auxiliary output classified as debugging information is directed to "standard error." Terminals themselves are also found as files here.
**"/etc"** (pronounced like the craft commerce site "Etsy," if you want to impress Linux veterans), is where many programs store their configuration files, which are used to change their settings. Some programs store copies of default configurations here, which are to be copied to another location before modification. Others store the one and only copy of the configuration here and expect users to modify it directly. Many programs reserved for the root user depend on this latter mode of configuration.
The **"/home"** directory is where users' personal files reside. For desktop users, this is where you spend most of your time. For every unprivileged user, there is a directory with corresponding name here.
**"/lib"** is home to the many libraries that your system depends on to run. Many programs employ one or more functions or subroutines that are common across dozens or hundreds of programs. So, instead of each program reproducing every component it needs within its binary, which would result in comparatively massive and inefficient programs, it references one or more of these libraries by making a "library call."
Removable media like USB flash drives or cameras are made accessible in the **"/media"** directory. While it is not present on all systems, it is common in distributions specializing in intuitive desktop systems, like Ubuntu. Media that has storage is "mounted" here, meaning that while the raw stream of bits from the device are found under "/dev", the file objects that users usually interact with are accessible here.
The **"/proc"** directory is a virtual filesystem that dynamically displays system data. What this means is that the system creates the contents of "/proc" on the fly, populating it with files that hold information about the system (such as hardware statistics) that is generated by virtue of running.
**"/tmp"** is, aptly enough, where temporary information like cached data is sent. There's really not much more to it than that.
Most program binaries on modern Linux systems are kept in the **"/usr"**directory. To unify the various directories containing binaries, "/usr" contains a copy of everything in "/bin", "/sbin", and "/lib".
Finally, **"/var"** is where data of "variable" length is kept. The kind of variable-length data found here is generally data that is expected to keep accumulating, like logs and caches. One example is the log your kernel keeps.
To keep your hard drive from filling up and crashing, "/var" has a built in "log rotate" function that deletes old information to make room for new information, maintaining a fixed maximum size.
### Poke Around
As I said, this is definitely not everything you'll find in the root directory, but it is a good start toward figuring out where your system's core functions reside -- and, moreover, what those functions are.
So, if you weren't sure what there was to learn, you probably have plenty of ideas now. If you want an even better idea, poke around in these directories for yourself!
--------------------------------------------------------------------------------
作者简介:
Jonathan Terrasi has been an ECT News Network columnist since 2017. His main interests are computer security (particularly with the Linux desktop), encryption, and analysis of politics and current affairs. He is a full-time freelance writer and musician. His background includes providing technical commentaries and analyses in articles published by the Chicago Committee to Defend the Bill of Rights.
------
via: http://www.linuxinsider.com/story/84658.html
作者:[Jonathan Terrasi ][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://www.linuxinsider.com/perl/mailit/?id=84658
[1]:http://www.linuxinsider.com/story/84658.html?rss=1#
[2]:http://www.linuxinsider.com/perl/mailit/?id=84658
[3]:http://www.linuxinsider.com/story/84658.html?rss=1
[4]:http://www.linuxfoundation.org/
[5]:http://www.linuxinsider.com/story/84658.html?rss=1
[6]:http://www.linuxinsider.com/story/84658.html?rss=1

View File

@ -0,0 +1,91 @@
文件系统层次标准FHS简介
============================================================
![linux](http://www.linuxinsider.com/article_images/story_graphics_xlarge/xl-2016-linux-1.jpg)
当你好奇地看着系统的根目录(“/”)的时候,可能会发现自己有点不知所措。大多数三个字母的目录名称并没有告诉你他们是做什么的,如果你需要做出一些重要的修改,那就很难知道在哪里可以查看。
我想给大家简单地介绍下根目录。
### 有用的工具
在我们开始之前,这里有几个值得熟悉的工具,它们可以让您随时挖掘您自己找到的有趣的东西。这些程序都不会对您的文件进行任何更改。
最有用的工具是 “ls” -- 它列出了使用完整路径或相对路径(即从当前目录开始的路径)作为参数给出的任何目录的内容。
$ ls  _path_
当您进一步深入文件系统时,重复输入长路径可能会变得很麻烦,所以如果您想简化这一操作,可以用 “cd” 替换 “ls” 来更改当前的工作目录到该目录。与 “ls” 一样,只需将目录路径作为 “cd” 的参数。
$ cd  _path_
如果您不确定某个文件是什么文件类型的,可以通过运行 “file” 并且将文件名作为“file” 命令的参数。
$ file  _filename_
最后,如果这个文件看起来像是人可读的,那么用 “less” 来看看(不用担心文件有改变)。与最后一个工具一样,给出一个文件名作为参数来查看它。
$ less  _filename_
完成文件扫描后,点击 “q” 退出,即可返回到您的终端。
### 根目录之旅
现在就开始我们的旅程。我将按照字母顺序介绍直接在根目录下的目录。这里并没有介绍所有的目录,但到最后,我们会突出其中的亮点。
我们将要完成的目录的所有分类和功能都基于 Linux 文件系统层次标准FHS。[Linux基金会][4]维护的 Linux FHS 通过规定其工具的各个组件应该存放的位置,帮助设计师和开发人员进行发行版和程序的开发。
通过将所有文件二进制文件和手册保存在程序中的一致性组织中FHS 让学习、调试或修改更加容易。想象一下,如果不是使用 “man” 命令找到使用指南,那么你就不得不寻找每个程序的手册。
按照字母顺序和结构顺序,我们从 “**bin**” 开始。该目录是包含 shell 命令的所有核心系统二进制文件(解释终端指令的程序)。没有这个目录的内容,你的系统就不能做很多事情。
接下来是 “**/boot**” 目录,它存储了您的计算机需要启动的所有东西。其中最重要的是引导程序和内核。引导程序是一个通过初始化一些基础工具,使引导过程继续进行的程序。在初始化结束时,引导程序会加载内核,内核允许计算机与所有其他硬件和固件进行接口。从这一点看,它可以持续地使整个操作系统工作。
“**/dev**” 目录是表示被系统识别为“设备”的所有文件的对象。这里包括许多显式的设备,如计算机的硬件组件:键盘,屏幕,硬盘驱动器等。
此外,“/dev” 还包含被系统视为“设备”的数据流的伪文件。一个例子是流入和流出您的终端的数据,可以分为三个“流”。它读取的信息被称为“标准输入”。命令或进程的输出是“标准输出”。最后,分类为调试信息的辅助输出指向“标准错误”。终端本身作为文件也可以在这里找到。
“**/etc**”(发音类似工艺商业网站 “Etsy”如果你想打动 Linux 老用户的话),许多程序在这里存储他们的配置文件,用于改变他们的设置。一些程序存储这里的是默认配置的副本,这些副本将在修改之前复制到另一个位置。其他的程序在这里存储配置的唯一副本,并期望用户可以直接修改。为 root 用户保留的许多程序取决于后一种配置模式。
“**/home**” 目录是用户个人文件所在的位置。对于桌面用户来说,这是您花费大部分时间的地方。对于每个非特权用户,这里都有一个具有相应名称的目录。
“**/lib**” 是您的系统依赖运行的许多库的所在地。许多程序都会重复使用一个或多个在几十上百个程序中常见的功能或子程序。所以,如果每个程序在其二进制文件中重写它需要的每一个组件,结果会是产生出一些大而无用的程序,作为更好的替代方案,我们可以通过进行“库调用”来引用这些库中的一个或多个。
在 “**/media**” 目录中可以访问像 USB 闪存驱动器或摄像机这样的可移动媒体。虽然它不存在于所有系统上,但在一些专注于直观桌面的系统中还是比较普遍的,如 Ubuntu。具有存储能力的媒体在此处被“挂载”这意味着当设备中的原始位流位于 “/dev” 目录下时,用户通常可以在这里访问那些可交互的文件对象。
“**/proc**” 目录是一个动态显示系统数据的虚拟文件系统。这意味着系统可以即时地创建 “/proc” 的内容,用包含运行时生成系统信息(如硬件统计信息)的文件进行填充。
“**/tmp**” 恰好足够的用于发送缓存数据等临时信息。这个目录不做其他更多的事情。
现代 Linux 系统上大多数程序的二进制文件保存在 “**/usr**” 目录中。为了统一包含二进制文件的各种目录,“/usr” 包含 “/bin”、“/sbin” 和 “/lib” 中的所有内容的副本。
最后,“**/var**” 里保存“可变”长度的数据。这里的可变长度数据的类型通常是会累积的数据,就像日志和缓存一样。一个例子是你的内核保留的日志。
为了保持硬盘远离空间用尽和崩溃的情况,“/var” 内置了“日志旋转”功能,可删除旧信息,为新信息腾出空间,维持固定的最大大小。
### 结尾
正如我所说,这里介绍的绝对不是您在根目录中可以找到的一切,但是确定系统核心功能所在地是一个很好的开始,而且可以更深入地研究这些功能是什么。
所以,如果你不知道要学习什么,就可能有很多的想法。如果你想得到一个更好的想法,就在这些目录中折腾自己吧!
--------------------------------------------------------------------------------
作者简介:
自 2017 年以来 Jonathan Terrasi 一直是 ECT 新闻网的专栏作家。他的主要兴趣是计算机安全(特别是 Linux 桌面),加密和分析政治和时事。他是全职自由作家和音乐家。他的背景包括在芝加哥委员会发表的保卫人权法案文章中提供技术评论和分析。
------
via: http://www.linuxinsider.com/story/84658.html
作者:[Jonathan Terrasi ][a]
译者:[firmianay](https://github.com/firmianay)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://www.linuxinsider.com/perl/mailit/?id=84658
[1]:http://www.linuxinsider.com/story/84658.html?rss=1#
[2]:http://www.linuxinsider.com/perl/mailit/?id=84658
[4]:http://www.linuxfoundation.org/