根据Unix FHS(Filesystem Hierarchy Standard)的建议,类Unix的文件系统遵循一定的标准,此只作为参考,而不是让编程人员当做手册。
root fs中的内容必须能够启动,恢复和修复系统。为了启动系统,需要在root分区装有足够的工具来挂载其他的文件系统,这些包括utilities, configuration, boot loader information等。
一级目录
root fs由于以下几点原因会被保持得比较小
1.偶尔会mount到非常小的设备上
2.root fs包含许多系统定制化的配置文件。比如定制化到某个系统的kernel等。意味着root fs通常不能再网络文件系统中共享。所以在网络系统中让它尽量小,可以姐还是呢过不共享文件占用的空间。
如下的目录和符号链接需要放入 /
Directory | Description |
---|---|
bin | Essential command binaries |
boot | Static files of the boot loader |
dev | Device files |
etc | Host-specific system configuration |
lib | Essential shared libraries and kernel modules |
media | Mount point for removeable media |
mnt | Mount point for mounting a filesystem temporarily |
opt | Add-on application software packages |
sbin | Essential system binaries |
srv | Data for services provided by this system |
tmp | Temporary files |
usr | Secondary hierarchy |
var | Variable data |
Directory | Description |
---|---|
home | User home directories (optional) |
lib<qual> | Alternate format essential shared libraries (optional) |
root | Home directory for the root user (optional) |
/bin
目的:当系统中没有其他文件系统被挂载时(如single user模式),包含着管理员和普通用户需要用到的命令。通常也被脚本间接地调用。
要求:/bin目录下不能含有子目录
如下需要放入/bin目录
Command | Description |
---|---|
cat | Utility to concatenate files to standard output |
chgrp | Utility to change file group ownership |
chmod | Utility to change file access permissions |
chown | Utility to change file owner and group |
cp | Utility to copy files and directories |
date | Utility to print or set the system data and time |
dd | Utility to convert and copy a file |
df | Utility to report filesystem disk space usage |
dmesg | Utility to print or control the kernel message buffer |
echo | Utility to display a line of text |
false | Utility to do nothing, unsuccessfully |
hostname | Utility to show or set the system's host name |
kill | Utility to send signals to processes |
ln | Utility to make links between files |
login | Utility to begin a session on the system |
ls | Utility to list directory contents |
mkdir | Utility to make directories |
mknod | Utility to make block or character special files |
more | Utility to page through text |
mount | Utility to mount a filesystem |
mv | Utility to move/rename files |
ps | Utility to report process status |
pwd | Utility to print name of current working directory |
rm | Utility to remove files or directories |
rmdir | Utility to remove empty directories |
sed | The `sed' stream editor |
sh | The Bourne command shell |
stty | Utility to change and print terminal line settings |
su | Utility to change user ID |
sync | Utility to flush filesystem buffers |
true | Utility to do nothing, successfully |
umount | Utility to unmount file systems |
uname | Utility to print system information |
Command | Description |
---|---|
csh | The C shell (optional) |
ed | The `ed' editor (optional) |
tar | The tar archiving utility (optional) |
cpio | The cpio archiving utility (optional) |
gzip | The GNU compression utility (optional) |
gunzip | The GNU uncompression utility (optional) |
zcat | The GNU uncompression utility (optional) |
netstat | The network statistics utility (optional) |
ping | The ICMP network test utility (optional) |
/boot:包含boot loader的静态文件
目的:此目录包含了启动过程中需要的一切。因此/boot目录存放的数据被使用时,kernel还没有运行用户态程序。
要求:操作系统内核必须放入/boot中。
/dev:存放设备文件
目的:
/etc:主机系统配置文件目录
目的:存放了配置文件。一个配置文件控制一个程序的操作,它必须是static,且不是可执行文件。
如果安装了如下子系统,如下的配置文件必须放入/etc中。
File | Description |
---|---|
csh.login | Systemwide initialization file for C shell logins (optional) |
exports | NFS filesystem access control list (optional) |
fstab | Static information about filesystems (optional) |
ftpusers | FTP daemon user access control list (optional) |
gateways | File which lists gateways for routed (optional) |
gettydefs | Speed and terminal settings used by getty (optional) |
group | User group file (optional) |
host.conf | Resolver configuration file (optional) |
hosts | Static information about host names (optional) |
hosts.allow | Host access file for TCP wrappers (optional) |
hosts.deny | Host access file for TCP wrappers (optional) |
hosts.equiv | List of trusted hosts for rlogin, rsh, rcp (optional) |
hosts.lpd | List of trusted hosts for lpd (optional) |
inetd.conf | Configuration file for inetd (optional) |
inittab | Configuration file for init (optional) |
issue | Pre-login message and identification file (optional) |
ld.so.conf | List of extra directories to search for shared libraries (optional) |
motd | Post-login message of the day file (optional) |
mtab | Dynamic information about filesystems (optional) |
mtools.conf | Configuration file for mtools (optional) |
networks | Static information about network names (optional) |
passwd | The password file (optional) |
printcap | The lpd printer capability database (optional) |
profile | Systemwide initialization file for sh shell logins (optional) |
protocols | IP protocol listing (optional) |
resolv.conf | Resolver configuration file (optional) |
rpc | RPC protocol listing (optional) |
securetty | TTY access control for root login (optional) |
services | Port names for network services (optional) |
shells | Pathnames of valid login shells (optional) |
syslog.conf | Configuration file for syslogd (optional) |
/home:用户根目录
/lib:必要的共享库和内核模块
目的: 此目录包含的libvrary images是启动系统时和在root fs运行命令时需要的,比如/bin 和/sbin
要求:下类文件需要放入此目录。
File | Description |
---|---|
libc.so.* | The dynamically-linked C library (optional) |
ld* | The execution time linker/loader (optional) |
/media:可且在媒体设备的挂载点
目的:此目录中的子目录是作为各种可卸载设备的挂载点,如floppy disks, cdroms .
/mnt:临时文件系统的挂载点
目的:做临时挂载用,此目录不能被安装程序使用,应该使用系统中空闲的目录作为替换。
/opt:附加的应用程序软件包,用于自行安装软件的位置,不过一般都安装在/usr/local中
目的:A package to be installed in /opt must locate its static files in a separate /opt/<package> or /opt/<provider> directory tree, where <package> is a name that describes the software package and <provider> is the provider's LANANA registered name.
/root:root user的Home目录
/sbin:系统二进制文件
目的:Utilities used for system administration (and other root-only commands) are stored in /sbin, /usr/sbin, and /usr/local/sbin. root用户的命令都是/sbin目录下的
/sbin contains binaries essential for booting, restoring, recovering, and/or repairing the system in addition to the binaries in /bin. [18] Programs executed after /usr is known to be mounted (when there are no problems) are generally placed into /usr/sbin. Locally-installed system administration programs should be placed into /usr/local/sbin.
如下执行文件应放入该目录下
Command | Description |
---|---|
fastboot | Reboot the system without checking the disks (optional) |
fasthalt | Stop the system without checking the disks (optional) |
fdisk | Partition table manipulator (optional) |
fsck | File system check and repair utility (optional) |
fsck.* | File system check and repair utility for a specific filesystem (optional) |
getty | The getty program (optional) |
halt | Command to stop the system (optional) |
ifconfig | Configure a network interface (optional) |
init | Initial process (optional) |
mkfs | Command to build a filesystem (optional) |
mkfs.* | Command to build a specific filesystem (optional) |
mkswap | Command to set up a swap area (optional) |
reboot | Command to reboot the system (optional) |
route | IP routing table utility (optional) |
swapon | Enable paging and swapping (optional) |
swapoff | Disable paging and swapping (optional) |
update | Daemon to periodically flush filesystem buffers (optional) |
/srv:系统提供的service data
/tmp:临时文件,
二级目录
/usr,s shareable, read-only data.
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.
要求:
Directory | Description |
---|---|
bin | Most user commands |
include | Header files included by C programs |
lib | Libraries |
local | Local hierarchy (empty after main installation) |
sbin | Non-vital system binaries |
share | Architecture-independent data |
/usr/bin: Most user commands
目的:这时系统中最主要的可执行命令
The following files, or symbolic links to files, must be in /usr/bin, if the corresponding subsystem is installed:
Command | Description |
---|---|
perl | The Practical Extraction and Report Language (optional) |
python | The Python interpreted language (optional) |
tclsh | Simple shell containing Tcl interpreter (optional) |
wish | Simple Tcl/Tk windowing shell (optional) |
expect | Program for interactive dialog (optional) |
/usr/include: Directory for standard include files.
目的:This is where all of the system's general-use include files for the C programming language should be placed.
/usr/lib: Libraries for programming and packages
目的:/usr/lib includes object files, libraries, and internal binaries that are not intended to be executed directly by users or shell scripts.
/usr/local: is for use by the system administrator when installing software locally.
The following directories, or symbolic links to directories, must be in /usr/local
Directory | Description |
---|---|
bin | Local binaries |
etc | Host-specific system configuration for local binaries |
games | Local game binaries |
include | Local C header files |
lib | Local libraries |
man | Local online manuals |
sbin | Local system binaries |
share | Local architecture-independent hierarchy |
src | Local source code |
/usr/sbin:Non-essential standard system binaries
/var:此目录包含的是可变数据文件。包括spool directory, log file等。
Directory | Description |
---|---|
cache | Application cache data |
lib | Variable state information |
local | Variable data for /usr/local |
lock | Lock files |
log | Log files and directories |
opt | Variable data for /opt |
run | Data relevant to running processes |
spool | Application spool data |
tmp | Temporary files preserved between system reboots |
一般还包含如下特殊目录:
Directory | Description |
---|---|
account | Process accounting logs (optional) |
crash | System crash dumps (optional) |
games | Variable game data (optional) |
User mailbox files (optional) | |
yp | Network Information Service (NIS) database files (optional) |
State information is generally used to preserve the condition of an application (or a group of inter-related applications) between invocations and between different instances of the same application. State information should generally remain valid after a reboot, should not be logging output, and should not be spooled data.
File | Description |
---|---|
lastlog | record of last login of each user |
messages | system messages from syslogd |
wtmp | record of all logins and logouts |
/var/spool: