casyup.me@outlook.com

0%

other/TopLevelDirectoriesMeansInLinux

Top Level Directories Means In Linux

It looks like I haven’t written some notes about Linux top-level directories. so do it now!

我好像还没写过关于 Linux 顶层文件含义的笔记, 那就现在写吧!

FROM

/: The top level directory in your system. It’s called the root directory, because it’s the root of the system: all the rest of the directory structure emanates from it like branches from the root of a tree. Don’t get confused by the /root directory, by the way; that’s a different ‘root’.

根节点, 叫 root 目录的时候, 有两种根据上下文不同而含义不同的选项: 根目录(/), root 用户根目录(/root)

/bin: Contains binaries for your system. The /bin directory is, by default, in your PATH, meaning that any executable file in this directory can be executed just by entering the file name at the command line.

二进制可执行文件目录. 通常会在 PATH 环境变量中, 执行的时候只需提供可执行文件名.

(PS: 所以有种直接执行当前目录而不带 ./ 前缀的方法是在 PATH 中加 . )

(我猜的, 实测可行! export PATH=$PATH:.)

/boot: Contains files necessary to boot your system, including the kernel.

包含启动系统必须的文件, 包括内核.

/dev: An abstracted directory which contains all your system devices: hard drives, CD-ROMs, sound cards, and much, much more. When devices are mounted, it occurs here.

虚拟文件目录, 所有可挂载设备都在这里.

/etc: Contains most of the system and application configuration files your Linux machine uses. Back this directory up regularly.

应用和系统的配置文件. 很重要, 所以请周期性保存它.

(PS: 为什么叫 etc 呢? etc 是等等的意思. 我记得之前查过, 最后得到的答案是, 历史原因… (╯▔皿▔)╯ )

/etc/skel: “skeleton” files used to create user accounts.

创建用户所需的文件?

( PS: 看了看, 包括三个文件 .profile .bashrc .bash_logout )

/home: Contains the home directory for each system user.

包含系统用户的 home 目录.

(PS: 不包含 root)

/lib: System modules, software libraries, & information databases, shared by various applications & the system itself.

系统模块, 软件/信息库.

/opt: Optional software that you installed.

可选软件安装目录.

/proc: Another abstracted directory which is created when the system boots. Contains information about the processes on your system.

系统运行创建的虚拟目录. 包含进程信息.

/root: The home directory of the root user.

root 的 home.

/sbin: Contains additional system binaries that are only available to root. Mostly admin tools.

admin 工具. 只对 root 开放.

/tmp: The temporary directory. Any user can place stuff in here, but be forewarned: your system periodically cleans out this directory, and anything you leave in here will be deleted.

临时文件目录

/usr: Contains subdirectories that will be used system-wide by all users, including binaries, libraries, man files, and other things.

包含所有用户使用的子目录, 包括二进制, 库, man 文件, 以及其他.

/usr/doc: Program documentation.

程序文档

/usr/info: Program documentation.

程序文档

/usr/lib: Program libraries (shareable system program modules).

程序库

/usr/man: Manual pages.

man 手册

/var: Contains variable data that changes in size as the system runs. For instance, log files, mail directories, databases, and printing spools.

随系统运行而改变的各种数据. 包括, 日志文件, 邮件目录, 数据库.

2020年3月31日

好像还有些遗漏, 不完全的, 补一下

FROM

/lost+found – Recovered Files

Each Linux file system has a lost+found directory. If the file system crashes, a file system check will be performed at next boot. Any corrupted files found will be placed in the lost+found directory, so you can attempt to recover as much data as possible.

每个文件系统都包含一个 lost+found 目录. 如果文件系统崩溃, 下次重启时会检查这个文件. 任何被发现的损坏文件都会放在这个目录下.

(PS: 部分不会, 比如 tmpfs 和 udev)

/mnt – Temporary Mount Points

Historically speaking, the /mnt directory is where system administrators mounted temporary file systems while using them. For example, if you’re mounting a Windows partition to perform some file recovery operations, you might mount it at /mnt/windows. However, you can mount other file systems anywhere on the system.

历史上来说, /mnt 目录包含系统管理员使用时挂载的临时文件系统. 比如, 如果你挂载一个 windows 分区执行一些文件恢复操作, 你应该挂载在 /mnt/windows 上. 然而, 你可以在系统任何地方挂载文件.

/opt – Optional Packages

The /opt directory contains subdirectories for optional software packages. It’s commonly used by proprietary software that doesn’t obey the standard file system hierarchy – for example, a proprietary program might dump its files in /opt/application when you install it.

包含可选软件包. 这通常用于不遵循标准文件系统层次的专有软件. 比如, 将会在安装时下载其文件到 /opt/application 的专有程序.

/run – Application State Files

The /run directory is fairly new, and gives applications a standard place to store transient files they require like sockets and process IDs. These files can’t be stored in /tmp because files in /tmp may be deleted.

一个程序存储其临时文件的地方, 这些文件不能存储到 /tmp, 因为里面的文件会被删除.

/srv – Service Data

The /srv directory contains “data for services provided by the system.” If you were using the Apache HTTP server to serve a website, you’d likely store your website’s files in a directory inside the /srv directory.

系统服务文件数据目录. 如果使用了 Apache HTTP 服务, 那么你应该把文件存储在这里.

(PS: Apache 默认目录是 ‘/var/www/html’ , 怎么更改? 还记得 /etc 的用处么?)

/usr – User Binaries & Read-Only Data

The /usr directory contains applications and files used by users, as opposed to applications and files used by the system. For example, non-essential applications are located inside the /usr/bin directory instead of the /bin directory and non-essential system administration binaries are located in the /usr/sbin directory instead of the /sbin directory. Libraries for each are located inside the /usr/lib directory. The /usr directory also contains other directories – for example, architecture-independent files like graphics are located in /usr/share.

包含用户使用的应用和文件, 而不是系统所使用的应用和文件.

The /usr/local directory is where locally compiled applications install to by default – this prevents them from mucking up the rest of the system.

/var – Variable Data Files

The /var directory is the writable counterpart to the /usr directory, which must be read-only in normal operation. Log files and everything else that would normally be written to /usr during normal operation are written to the /var directory. For example, you’ll find log files in /var/log.

与 /usr 相比, 是一个可写入的目录. 日志及其他通常会写入 /usr 的数据都会写入到 /var 目录.