Draft:Linux/目錄結構
外觀
在Linux下有一些目錄是固定存在用於系統的,包括以下這些:
目錄 | 用途 |
---|---|
/ | 根目錄 |
/var | 經常被修改的文件,包括各種日誌 |
/bin | 二進制可執行文件 |
/etc | 系統管理所需要的配置文件 |
/sbin | 特殊的二進制可執行文件 |
/usr | Unix system resources或"universal system resources"的縮寫 |
/usr/lib | 已安裝的程序相關文件 |
/mnt (或 /media) | 掛載的有文件系統的設備 |
/dev | 代表設備的文件 |
/boot | 啟動器和內核相關的文件 |
/lib | 最基本的動態連接共享庫 |
/home | 存放用戶的家目錄 |
除自己的家目錄外,用戶不能在任何目錄中寫入內容(比如用戶pietje只能在 /home/pietje 目錄中寫入內容)。只有root用戶可以寫入其他目錄,並允許其他人寫入其他目錄。除非root用戶進行限制,否則任何人都可以讀取所有目錄。
/bin
: Contains basic commands needed for navigation and for the system's initialization scripts./boot
: Generally contains everything needed to boot, including the kernel and its configuration files and any files needed at runtime by your bootloader.- Note: "Boot" does not mean get your system into a useful state. It simply means fully execute the kernel and any modules needed to complete that mission.
/dev
: Device files. In UNIX/Linux, it's often said, "everything is a file." In/dev
you will find file representations of physical and virtual devices. Different devices have different representations, and can be interacted with in different ways. For example, you cancat
a raw wav file into/dev/dsp
(Digital Sound Processor, your sound card) to hear it. You can use thedd
command line tool to interact with/dev/random
to produce a stream of random data./etc
: Contains your systemwide configuration files. Many of these files and directories will be application-specific (you may have/etc/postfix
or/etc/sendmail
, but seldom both), but some applications are common across most if not all UNIX/Linux flavors and so some files will be on every UNIX/Linux system (with the same purpose), such as:/etc/hosts
: Described above./etc/resolv.conf
: Contains information on how to resolve hostnames, such as IP addresses of nameservers. Like many system config files, more information can be found on/etc/resolv.conf
on most systems by sayingman resolv.conf
/etc/crontab
: Tables for driving cron, an execution scheduler. There are multiple man pages for crontab. Tryman 5 crontab
for information on the file, andman 8 crontab
for information on the program. Also see the section below on man for more information./etc/fstab
: Information necessary for mounting your filesystems, including network and other virtual filesystems. Tryman fstab
for more information./etc/hostname
: The file typically containing the system's hostname. The hostname is set at boot time by reading this file, so one way to change your hostname is to edit this file and reboot. Systems are not required to have this particular file, so it has no man page (on most systems)./etc/passwd
: Despite its name, this file doesn't usually contain any password information. Instead it has a line for each user, including username, userid, groupid, full name, home directory and login shell. Most systems come with a tool to allow you to safely edit the file (by doing lint checking when you save) calledvipw
, which will launch theEDITOR
environment variable (usuallyvim
ornano
) to edit the file with failsafes./etc/shadow
: Contains user password information, stored cryptographically using a one-way hash. It's worth noting the way this works. The password, when set, is encrypted using a mathematical algorithm that, in theory, cannot be reversed, so the password cannot be decrypted. When you login, the same math is applied to the supplied password. The result is compared with the value in/etc/shadow
, and if the encrypted strings match, you are allowed to log in./etc/sudoers
: Not every system hassudo
installed, so not every system will have this file. If your system doesn't have sudo installed, you'll want to install it right away and add yourself as a sudoer. Sayman sudoers
for more info, and usevisudo
(similar tovipw
) to edit the file.
/home
: User home directories. For most systems, this should be on its own partition. This will allow a system administrator to migrate to another Linux distro or even operating system, for example, without losing or having to migrate their data and user-specific configurations. Simply install the new OS without formacodeing this partition. Another benefit is that a user who uses too much space (if filesystem quotas aren't set up) won't be able to fill up the system's available space, which can be an administrative headache./lib
: Contains shared libraries needed to start your system. Shared library filenames typically end in .so, sometimes followed by dots and numbers indicating version information. They are analogous to.dll
files in Windows - they contain functionality shared by multiple executable files, such as reading from and writing to files, etc. This particular directory contains shared libraries required by executables in/bin
and/sbin
./media
: Mount point for removable media. This is where your CDROM drive, USB sticks, floppies, etc. will generally be mounted. Implementation varies by distribution/OS, but a mounted CDROM drive may be accessed through (for example)/media/cdrom
./mnt
: Temporary mount point for arbitrary filesystems. You may temporarily mount, for example, a remote SMB filesystem, a loopback device (like a mounted ISO file), or an actual partition on the machine here. Seeman mount
./opt
: 3rd party software. What's generally installed here is binary-only software not compiled for a specific distribution. For example, if you download and install [hcodep://www.google.com/earth/index.html Google Earth], it will be installed here by default. It is statically compiled, meaning it shouldn't require any libraries specific to your system, which means it should be portable across distributions. That distinguishes it from most other applications on your system. If you use a lot of these applications, it may be a good idea to also make/opt
a separate partition, since it should be portable across distributions and distribution versions, like/home
./root
: Root's home directory./sbin
: System binaries. Like/bin
except that these binaries are generally only usable by the superuser, or root./tmp
: Temporary files. On most modern UNIX/Linux operating systems, this is a special filesystem, like tmpfs, occupying a specific amount of space. It should have the "sticky" filesystem attribute set, meaning any user can create files here, but users cannot edit each other's files./usr
: Almost a filesystem unto itself,/usr
contains shareable, read-only files. Shareable in this context means that the files are not host-specific. You sould be able to share these files with another host, which would mount/usr
remotely and be able to use its contents.