Most of the Linux distributions follow the Filesystem Hierarchy Standard (FHS) quite well.
FHS:Filesystem Hierarchy Standard 提取码: hqcz
参考:https://www.cnblogs.com/kzloser/articles/2673771.html
Table of Contents
FHS(Filesystem Hierarchy Standard):
FHS(Filesystem Hierarchy Standard):
FHS依据文件系统使用的频繁与否与是否允许使用者随意更动, 而将目录定义成为四种交互作用的形态,用表格来说有点像底下这样:
可分享的(shareable) | 不可分享的(unshareable) | |
不变的(static) | /usr (软件放置处) | /etc (配置文件) |
/opt (第三方协力软件) | /boot (开机与核心档) | |
可变动的(variable) | /var/mail (使用者邮件信箱) | /var/run (程序相关) |
/var/spool/news (新闻组) | /var/lock (程序相关) |
- 可分享的:可以分享给其他系统挂载使用的目录,所以包括执行文件与用户的邮件等数据, 是能够分享给网络上其他主机挂载用的目录;
- 不可分享的:自己机器上面运作的装置文件或者是与程序有关的socket文件等, 由于仅与自身机器有关,所以当然就不适合分享给其他主机了.
- 不变的:有些数据是不会经常变动的,跟随着distribution而不变动. 例如函式库、文件说明文件、系统管理员所管理的主机服务配置文件等等;
- 可变动的:经常改变的数据,例如登录文件、一般用户可自行收受的新闻组等.
事实上,FHS针对目录树架构仅定义出三层目录底下应该放置什么数据而已,分别是底下这三个目录的定义:
- / (root, 根目录):与开机系统有关;
- /usr (unix software resource):与软件安装/执行有关;
- /var (variable):与系统运作过程有关.
根目录 (/) 的意义与内容:
概要:
- 所有的目录都是由根目录衍生出来的(根目录是整个系统最重要的一个目录)
- 与开机/还原/系统修复等动作有关. (由于系统开机时需要特定的开机软件、核心文件、开机所需程序、 函式库等等文件数据,若系统出现错误时,根目录也必须要包含有能够修复文件系统的程序才行)
- FHS标准建议:根目录(/)所在分割槽应该越小越好, 且应用程序所安装的软件最好不要与根目录放在同一个分割槽内,保持根目录越小越好.(因为越大的分割槽妳会放入越多的数据,如此一来根目录所在分割槽就可能会有较多发生错误的机会,如此不但效能较佳,根目录所在的文件系统也较不容易发生问题.)
重要的目录(简单)
The most important directories and their contents:
/bin Essential(极其重要的) user command binaries that need to be available also in single user mode(单用户模式).
/sbin Essential system binaries (e.g. init, insmod, ifup)
/lib Libraries for the binaries in /bin and /sbin
/usr/bin Non-essential user command binaries that are not needed in single user mode
/usr/sbin Non-essential system binaries (e.g. daemons for network-services)
/usr/lib Libraries for the binaries in /usr/bin and /usr/sbin
/etc Host-specific system-wide configuration files
/dev Device files
/home User home directories (optional)
/proc Virtual file system documenting kernel and process status as text files
根目录(/)底下目录FHS定义的说明:
目录 | 应放置文件内容 |
/bin | 系统有很多放置执行文件的目录,但/bin比较特殊.因为/bin放置的是在单人维护模式下还能够被操作的指令. 在/bin底下的指令可以被root与一般账号所使用,主要有:cat, chmod, chown, date, mv, mkdir, cp, bash等等常用的指令.
/bin contains commands that may be used by both the system administrator and by users, but which are |
/boot | 这个目录主要在放置开机会使用到的文件,包括Linux核心文件以及开机选单与开机所需配置文件等等. Linux kernel常用的档名为:vmlinuz,如果使用的是grub这个开机管理程序, 则还会存在/boot/grub/这个目录喔!
This directory contains everything required for the boot process except configuration files not needed at |
/dev | 在Linux系统上,任何装置与接口设备都是以文件的型态存在于这个目录当中的. 你只要透过存取这个目录底下的某个文件,就等于存取某个装置啰~ 比要重要的文件有/dev/null, /dev/zero, /dev/tty, /dev/lp*, /dev/hd*, /dev/sd*等等
The /dev directory is the location of special or device files. |
/etc | 系统主要的配置文件几乎都放置在这个目录内,例如人员的账号密码文件、 各种服务的启始档等等.一般来说,这个目录下的各文件属性是可以让一般使用者查阅的, 但是只有root有权力修改.FHS建议不要放置可执行文件(binary)在这个目录中喔.比较重要的文件有: /etc/inittab, /etc/init.d/, /etc/modprobe.conf, /etc/X11/, /etc/fstab, /etc/sysconfig/ 等等.另外,其下重要的目录有:
The /etc hierarchy contains configuration files. A "configuration file" is a local file used to control the |
/home | 这是系统默认的用户家目录(home directory).在你新增一个一般使用者账号时, 默认的用户家目录都会规范到这里来.比较重要的是,家目录有两种代号喔:
/home is a fairly standard concept, but it is clearly a site-specific filesystem. The setup will differ from |
/lib | 系统的函式库非常的多,而/lib放置的则是在开机时会用到的函式库, 以及在/bin或/sbin底下的指令会呼叫的函式库而已. 什么是函式库呢?妳可以将他想成是『外挂』,某些指令必须要有这些『外挂』才能够顺利完成程序的执行之意. 尤其重要的是/lib/modules/这个目录, 因为该目录会放置核心相关的模块(驱动程序)喔!
The /lib directory contains those shared library images needed to boot the system and run the commands |
/media | media是『媒体』的英文,顾名思义,这个/media底下放置的就是可移除的装置啦! 包括软盘、光盘、DVD等等装置都暂时挂载于此.常见的档名有:/media/floppy, /media/cdrom等等.
This directory contains subdirectories which are used as mount points for removable media such as floppy |
/mnt | 如果妳想要暂时挂载某些额外的装置,一般建议妳可以放置到这个目录中. 在古早时候,这个目录的用途与/media相同啦!只是有了/media之后,这个目录就用来暂时挂载用了.
This directory is provided so that the system administrator may temporarily(暂时的) mount a filesystem as needed. This directory must not be used by installation programs: a suitable temporary directory not in use by the |
/opt | 这个是给第三方协力软件放置的目录.什么是第三方协力软件啊? 举例来说,KDE这个桌面管理系统是一个独立的计划,不过他可以安装到Linux系统中,因此KDE的软件就建议放置到此目录下了. 另外,如果妳想要自行安装额外的软件(非原本的distribution提供的),那么也能够将你的软件安装到这里来. 不过,以前的Linux系统中,我们还是习惯放置在/usr/local目录下呢!
/opt is reserved for the installation of add-on application software packages. |
/root | 系统管理员(root)的家目录.之所以放在这里,是因为如果进入单人维护模式而仅挂载根目录时, 该目录就能够拥有root的家目录,所以我们会希望root的家目录与根目录放置在同一个分割槽中.
The root account's home directory may be determined by developer or local preference, but this is the |
/sbin | Linux有非常多指令是用来设定系统环境的,这些指令只有root才能够利用来『设定』系统,其他用户最多只能用来『查询』而已. 放在/sbin底下的为开机过程中所需要的,里面包括了开机、修复、还原系统所需要的指令. 至于某些服务器软件程序,一般则放置到/usr/sbin/当中.至于本机自行安装的软件所产生的系统执行文件(system binary), 则放置到/usr/local/sbin/当中了.常见的指令包括:fdisk, fsck, ifconfig, init, mkfs等等.
Utilities used for system administration (and other root-only commands) are stored in /sbin, /usr/ |
/srv | srv可以视为『service』的缩写,是一些网络服务启动之后,这些服务所需要取用的数据目录. 常见的服务例如WWW, FTP等等.举例来说,WWW服务器需要的网页数据就可以放置在/srv/www/里面.
/srv contains site-specific data which is served by this system. |
/tmp | 这是让一般使用者或者是正在执行的程序暂时放置文件的地方. 这个目录是任何人都能够存取的,所以你需要定期的清理一下.当然,重要数据不可放置在此目录啊! 因为FHS甚至建议在开机时,应该要将/tmp下的数据都删除唷!
The /tmp directory must be made available for programs that require temporary files. |
/run | This directory contains system information data describing the system since it was booted. Files under this directory must be cleared (removed or truncated as appropriate) at the beginning of the boot process. The purposes of this directory were once served by /var/run. In general, programs may continue to use /var/run to fulfill the requirements set out for /run for the purposes of backwards compatibility. Programs which have migrated to use /run should cease their usage of /var/run, except as noted in the section on /var/run. Programs may have a subdirectory of /run; this is encouraged for programs that use more than one run- time file. Users may also have a subdirectory of /run, although care must be taken to appropriately limit access rights to prevent unauthorized use of /run itself and other subdirectories. 17 |
除上 FHS 中定义的目录说明外, 底下是几个在Linux当中非常重要的目录:
目录 | 应放置文件内容 |
/lost+found | 这个目录是使用标准的ext2/ext3文件系统格式才会产生的一个目录,目的在于当文件系统发生错误时, 将一些遗失的片段放置到这个目录下.这个目录通常会在分割槽的最顶层存在, 例如你加装一颗硬盘于/disk中,那在这个系统下就会自动产生一个这样的目录『/disk/lost+found』 |
/proc | 这个目录本身是一个『虚拟文件系统(virtual filesystem)』喔!他放置的数据都是在内存当中, 例如系统核心、行程信息(process)、周边装置的状态及网络状态等等.因为这个目录下的数据都是在内存当中, 所以本身不占任何硬盘空间啊!比较重要的文件例如:/proc/cpuinfo, /proc/dma, /proc/interrupts, /proc/ioports, /proc/net/* 等等. |
/sys | 这个目录其实跟/proc非常类似,也是一个虚拟的文件系统,主要也是记录与核心相关的信息. 包括目前已加载的核心模块与核心侦测到的硬件装置信息等等.这个目录同样不占硬盘容量喔! |
/usr 的意义与内容:
概要:
- 依据FHS的基本定义,/usr里面放置的数据属于可分享的与不可变动的(shareable, static), 如果你知道如何透过网络进行分割槽的挂载,那么/usr确实可以分享给局域网络内的其他主机来使用!
- usr(Unix Software Resource 即Unix操作系统软件资源) FHS建议所有软件开发者,应该将他们的数据合理的分别放置到这个目录下的次目录,而不要自行建立该软件自己独立的目录.
- 所有系统默认的软件(distribution发布者提供的软件)都会放置到/usr底下,因此这个目录有点类似Windows 系统的『C:\Windows\ + C:\Program files\』这两个目录的综合体,系统刚安装完毕时,这个目录会占用最多的硬盘容量.
/usr is the second major section of the filesystem. /usr is shareable, read-only data. That means
that /usr should be shareable between various FHS-compliant hosts and must not be written to. Any
information that is host-specific or varies with time is stored elsewhere.
Large software packages must not use a direct subdirectory under the /usr hierarchy.
一般来说,/usr的次目录建议有底下这些:
目录 | 应放置文件内容 |
/usr/X11R6/ | 为X Window System重要数据所放置的目录,之所以取名为X11R6是因为最后的X版本为第11版,且该版的第6次释出之意. |
/usr/bin/ | 绝大部分的用户可使用指令都放在这里!请注意到他与/bin的不同之处.(是否与开机过程有关)
This is the primary directory of executable commands on the system. |
/usr/include/ | c/c++等程序语言的档头(header)与包含档(include)放置处,当我们以tarball方式 (*.tar.gz 的方式安装软件)安装某些数据时,会使用到里头的许多包含档喔!
This is where all of the system's general-use include files for the C programming language should be placed. |
/usr/lib/ | 包含各应用软件的函式库、目标文件(object file),以及不被一般使用者惯用的执行档或脚本(script). 某些软件会提供一些特殊的指令来进行服务器的设定,这些指令也不会经常被系统管理员操作, 那就会被摆放到这个目录下啦.要注意的是,如果你使用的是X86_64的Linux系统, 那可能会有/usr/lib64/目录产生喔!
/usr/lib includes object files and libraries. On some systems, it may also include internal binaries |
/usr/local/ | 系统管理员在本机自行安装自己下载的软件(非distribution默认提供者),建议安装到此目录, 这样会比较便于管理.举例来说,你的distribution提供的软件较旧,你想安装较新的软件但又不想移除旧版, 此时你可以将新版软件安装于/usr/local/目录下,可与原先的旧版软件有分别啦! 你可以自行到/usr/local去看看,该目录下也是具有bin, etc, include, lib...的次目录喔!
The /usr/local hierarchy is for use by the system administrator when installing software locally. It |
/usr/sbin/ | 非系统正常运作所需要的系统指令.最常见的就是某些网络服务器软件的服务指令(daemon)啰!
This directory contains any non-essential binaries used exclusively by the system administrator. System administration programs that are required for system repair, system recovery, mounting /usr, or other |
/usr/share/ | 放置共享文件的地方,在这个目录下放置的数据几乎是不分硬件架构均可读取的数据, 因为几乎都是文本文件嘛!在此目录下常见的还有这些次目录:
The /usr/share hierarchy is for all read-only architecture independent data files.
|
/usr/src/ | 一般原始码建议放置到这里,src有source的意思.至于核心原始码则建议放置到/usr/src/linux/目录下.
Source code may be placed in this subdirectory, only for reference purposes. |
/var 的意义与内容:
概要:
/var目录主要针对常态性变动的文件,包括缓存(cache)、登录档(log file)以及某些软件运作所产生的文件, 包括程序文件(lock file, run file),或者例如MySQL数据库的文件等等. 所以/var在系统运作后才会渐渐占用硬盘容量的目录
/var contains variable data files. This includes spool directories and files, administrative and logging
data, and transient and temporary files.
常见的次目录有:
目录 | 应放置文件内容 |
/var/cache/ | 应用程序本身运作过程中会产生的一些暂存档;
/var/cache is intended for cached data from applications. Such data is locally generated as a result of |
/var/lib/ | 程序本身执行的过程中,需要使用到的数据文件放置的目录.在此目录下各自的软件应该要有各自的目录. 举例来说,MySQL的数据库放置到/var/lib/mysql/而rpm的数据库则放到/var/lib/rpm去!
This hierarchy holds state information pertaining to an application or the system. State information is data State information is generally used to preserve the condition of an application (or a group of inter- |
/var/lock/ | 某些装置或者是文件资源一次只能被一个应用程序所使用,如果同时有两个程序使用该装置时, 就可能产生一些错误的状况,因此就得要将该装置上锁(lock),以确保该装置只会给单一软件所使用. 举例来说,刻录机正在刻录一块光盘,你想一下,会不会有两个人同时在使用一个刻录机烧片? 如果两个人同时刻录,那片子写入的是谁的数据?所以当第一个人在刻录时该刻录机就会被上锁, 第二个人就得要该装置被解除锁定(就是前一个人用完了)才能够继续使用啰.
Lock files should be stored within the /var/lock directory structure. |
/var/log/ | 重要到不行!这是登录文件放置的目录!里面比较重要的文件如/var/log/messages, /var/log/wtmp(记录登入者的信息)等.
This directory contains miscellaneous(各种各样的) log files. Most logs must be written to this directory or an appropriate subdirectory. |
/var/mail/ | 放置个人电子邮件信箱的目录,不过这个目录也被放置到/var/spool/mail/目录中! 通常这两个目录是互为链接文件啦!
The mail spool must be accessible through /var/mail and the mail spool files must take the form |
/var/run/ | 某些程序或者是服务启动后,会将他们的PID放置在这个目录下喔! 至于PID的意义我们会在后续章节提到的.
This directory was once intended for system information data describing the system since it was booted. |
/var/spool/ | 这个目录通常放置一些队列数据,所谓的『队列』就是排队等待其他程序使用的数据啦! 这些数据被使用后通常都会被删除.举例来说,系统收到新信会放置到/var/spool/mail/中, 但使用者收下该信件后该封信原则上就会被删除.信件如果暂时寄不出去会被放到/var/spool/mqueue/中, 等到被送出后就被删除.如果是工作排程数据(crontab),就会被放置到/var/spool/cron/目录中!
/var/spool contains data which is awaiting some kind of later processing. Data in /var/spool |
目录树(directory tree):
在Linux底下,所有的文件与目录都是由根目录开始的!然后再一个一个的分支下来,有点像是树枝状.因此,我们也称这种目录配置方式为:『目录树(directory tree)』它主要的特性有:
- 目录树的启始点为根目录 (/, root);
- 每一个目录不止能使用本地端的 partition 的文件系统,也可以使用网络上的 filesystem 。举例来说, 可以利用 Network File System (NFS) 服务器挂载某特定目录等。
- 每一个文件在此目录树中的文件名(包含完整路径)都是独一无二的。
如果我们将整个目录树以图标的方法来显示,并且将较为重要的文件数据列出来的话,那么目录树架构有点像这样:
图释一:
图释二:
注意:上表解释有点问题而且是繁体字,可不看