Linux directory structure

本文深入解析Linux目录结构,从根目录开始,逐步介绍每个主要目录的功能、内容及其用途,包括/bin、/sbin、/etc、/dev、/tmp等常见目录,帮助用户理解Linux文件系统的组织方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Have you ever looked in your / directory, you’ll see a lot of directories. Here we are presenting beginners guide to linux directory structure explaining what they mean and what are the contents of these directories.

Screenshot of contents of root directory:

linux directory structure

 

/

This is called root partition. All files and directories start with root partition. Write privileges under this directory are avaible with root user only. Not to confuse it with root user’s home directory, know the difference, “/” is root partition while root user’s home directory is “/root”.

/bin

This directory has binary executable files. Linux commands used in single user mode are found in this directory. It also holds commands that are used by all users. Examples: ls, ping, cp.

/sbin

Like /bin, /sbin also contains binary executable files but the commands held by this directory are used by system administrators with the prime purpose of system maintenance. Examples: iptables, reboot, fdisk.

/etc

It holds all the configuration files which are required by all programs. Shell scripts needed by programs to start or stop them are held by this very directory. Examples are /etc/resolv.conf, /etc/logrotate.conf

/dev

/dev contains device files. In Linux, everything is a file. Included are terminal device or usb or any other device connected to the computer. For example: /dev/usbmon0

/proc

All the system process information is held in /proc. It is a pseudo filesystem as it contains information about running processes. For an instance, /proc/ is the directory which holds information of the process with . It contains information about the system resources. /proc/uptime is one such directory.

/var

var denotes variable files. Those files are kept in this directory that are supposed to grow. Some of the files that reside in here are- /var/log (system log files), /var/lib (package files), /var/mail (emails), /var/spool (print queues), /var/tmp (temporary files that are needed across reboots).

/tmp

System generated and user generated temporary files are kept in this category. Important files should not be saved in here because contents of /tmp are flushed every time system boots.

/usr

/usr is the one that holds user programs. It contains documentations, libraries and source-code for all the second level applications. /usr/bin holds binaries for user programs. While looking for a binary after /bin also look in /usr/bin. Examples of binaries you mighht find in /usr/bin are awk, less, cc. Similarly binary files for system administrators are kept in /usr/sbin. Examples are cron, sshd, useradd. Libraries for /usr/bin and /usr/sbin are kept in /usr/lib. /usr/local holds user programs that a user installs from source.

/home

All user’s personal files are kept in their respective home directories.

/boot

This directory has boot loader files. While booting, files needed are found in /boot. Kernel initrd, grub and few more files reside in this directory.

/lib

Binaries located in /bin and /sbin are supported by library files kept in /lib. Library nomenclature goes like ld* or lib*.so.* . For example: ld-2.11.1.so

/opt

/opt is for add-on optional applications from individual vendors. All applications that are optional should be installed in /opt or any of its subdirectory.

/mnt

/mnt is our mount directory. It is the temporary mount location where where system administrators can mount temporary filesystems.

/media

It serves as the temporary mount point for removable devices. All removable devices are mounted in this directory. Example: /media/cdrom or /media/floppy.

/srv

<think>首先,用户的问题是:“我想查看Linux系统中systemd服务的日志信息 请问how to check systemd service logs in Linux”。这是一个关于如何在Linux系统中查看systemd服务日志的查询。 我需要根据系统级指令来构建回答: - 所有行内数学表达式必须使用$...$格式。 - 独立公式使用$$...$$格式并单独成段。 - LaTeX语法正确。 - 使用中文回答。 - 生成相关问题。 - 在回答中引用的段落末尾自然地添加引用标识,例如[^1]。 用户可见层的指令: - 回答结构清晰,帮助用户逐步解决问题。 - 保证回答真实可靠。 参考的站内引用: - [^1]: A Linux machine with systemd writes the logs to /var/log/journal directory. If you remember the Linux directory structure, /var is where the system logs are stored. - [^2]: English 环境 Red Hat Enterprise Linux 7.3+ Systemd 问题 What command can I use to determine the "literal/actual" start-up sequence of service units (get date/time) and/or which log files should I check? I know I can use systemd-analyze to get dependency info, but I want to know that actual start-up times/order/logs of specific services. 决议 - [^3]: systemd linux_Systemd将改变Linux主目录的工作方式。 systemd背后的团队希望您采用一种管理主目录的新方法。 称其为“新方法”是轻描淡写-这是Linux的真正范式转变。 这是有关systemd-homed的所有信息,您可能会发现附近的Linux发行版。 毫无争议 (No Stranger to Controversy) - [^4]: By default in Linux there are a few different mechanisms in place that may rate limit logging. These are primarily the systemd journal and rsyslog rate limits that are in place by default. - [^5]: How to install Postgresql 10 in Linux Mint 18 OverviewAdd souresUpdate apt cacheInstallConfigurationAccountEnable remote access pgadmin4PSQLReference 这些引用提供了关于systemd日志位置和工具的信息。特别是: - [^1] 提到日志存储在/var/log/journal目录。 - [^2] 讨论了使用systemd-analyze和日志文件来查看服务启动顺序。 - [^4] 提到日志速率限制。 在回答中,我需要自然地引用这些内容。用户的问题是关于查看systemd服务日志,所以我应该基于这些引用提供步骤。 关键点: - systemd使用journald来管理日志。 - 主要工具是journalctl。 - 日志存储在/var/log/journal。 步骤: 1. 使用journalctl命令查看日志。 2. 指定服务名称。 3. 其他选项如实时查看、过滤等。 结构化回答: - 介绍:简要解释systemd日志系统。 - 步骤:逐步指导如何使用journalctl。 - 引用:在相关部分添加引用标识。 - 相关问题:生成相关问题。 确保使用中文回答。 生成相关问题: - 基于用户查询,生成相关的问题,如如何过滤日志、如何查看特定时间日志等。 最终回答结构: 1. 标题或开头。 2. 步骤部分。 3. 相关问题部分。</think>### 如何查看 Linux 系统中 systemd 服务的日志信息 在 Linux 系统中,systemd 服务使用 `journald` 守护进程来管理日志,这些日志默认存储在 `/var/log/journal` 目录下[^1]。查看日志的主要工具是 `journalctl` 命令,它提供了强大的过滤和查询功能。下面我将逐步指导您如何操作,确保回答真实可靠(基于 Linux 社区最佳实践和文档)。 #### 步骤 1: 基本命令查看所有日志 - 打开终端(Terminal),输入以下命令查看所有 systemd 服务的日志: ```bash journalctl ``` 这会显示完整的日志输出,按时间排序。您可以使用箭头键或 Page Up/Down 导航日志。 - **注意**:如果日志文件较大,输出可能很长。添加 `-b` 选项可以只显示当前启动周期的日志,例如: ```bash journalctl -b ``` #### 步骤 2: 查看特定服务的日志 - 要查看单个服务的日志,使用 `-u` 选项后跟服务名称。例如,查看 `nginx` 服务的日志: ```bash journalctl -u nginx.service ``` 替换 `nginx.service` 为您要查询的服务名(如 `sshd.service` 或 `docker.service`)。 - **提示**:服务名通常以 `.service` 结尾,您可以通过 `systemctl list-units --type=service` 列出所有服务。 #### 步骤 3: 实时监控日志 - 如果需要实时跟踪日志更新(如调试服务启动问题),添加 `-f` 选项: ```bash journalctl -u your-service.service -f ``` 按 `Ctrl+C` 退出实时模式。此功能对于诊断服务启动顺序或错误非常有用,类似于 `systemd-analyze` 但更侧重于实际日志内容[^2]。 #### 步骤 4: 高级过滤和选项 - **按时间过滤**:使用 `--since` 和 `--until` 指定时间范围。例如,查看过去一小时的日志: ```bash journalctl --since "1 hour ago" ``` - **按优先级过滤**:只显示错误消息(如 `error` 或 `critical`): ```bash journalctl -p err ``` 优先级范围是 `0` (emerg) 到 `7` (debug),使用数字或名称(如 `-p 3` 表示错误)。 - **导出日志**:将日志保存到文件: ```bash journalctl -u your-service.service > service_log.txt ``` - **注意速率限制**:默认情况下,systemd 可能对日志进行速率限制以防止磁盘溢出[^4]。如果日志缺失,检查 `/etc/systemd/journald.conf` 中的 `RateLimitInterval` 和 `RateLimitBurst` 设置。 #### 常见问题解决 - **日志文件位置**:所有日志存储在 `/var/log/journal/` 下,但直接访问文件不如使用 `journalctl` 安全(因为日志是二进制格式)。使用 `journalctl --file=/var/log/journal/*/system.journal` 可指定文件路径[^1]。 - **权限问题**:普通用户可能无法查看所有日志。添加 `sudo` 提升权限: ```bash sudo journalctl ``` - **日志轮转**:systemd 自动管理日志大小,旧日志归档在 `/var/log/journal` 子目录中。使用 `journalctl --vacuum-size=100M` 清理旧日志。 通过以上步骤,您可以高效地查看和分析 systemd 服务日志。如果需要更深入的工具(如分析启动顺序),`systemd-analyze` 可结合日志使用[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值