Skip to content
← 返回Linux列表
命令与系统观察

Linux:进程、服务与资源 ​

检查状态与定位问题 ​

iostat(Linux) · 报告设备和分区的统计信息 ​

更多信息:https://manned.org/iostat。

  • 显示系统启动以来的CPU和磁盘统计报告:
bash
iostat
  • 以MB为单位显示CPU和磁盘统计报告:
bash
iostat -m
  • 显示CPU统计信息:
bash
iostat -c
  • 显示包含磁盘名称(含LVM)的磁盘统计信息:
bash
iostat -N
  • 显示设备"sda"的扩展磁盘统计信息(包含磁盘名称):
bash
iostat -xN {{sda}}
  • 每2秒显示一次CPU和磁盘的增量统计报告:
bash
iostat {{2}}

pgrep(Linux) · 按名称或其他属性查找进程 ​

另请参阅:pidof。 更多信息:https://manned.org/pgrep。

  • 返回命令字符串匹配的所有正在运行进程的 PID:
bash
pgrep {{进程名称}}
  • 同时显示完整命令:
bash
pgrep {{[-a|--list-full]}} {{进程名称}}
  • 搜索进程时包含其命令行选项:
bash
pgrep {{[-f|--full]}} "{{进程名称}} {{参数}}"
  • 搜索由特定用户运行的进程:
bash
pgrep {{[-u|--euid]}} {{用户名}} {{进程名称}}

格式化、测试与性能检查 ​

tmt(Linux) · 创建、运行和调试测试的测试管理工具 ​

诸如运行、尝试等子命令,均有相应的用法文档。 更多信息:https://tmt.readthedocs.io/en/stable/examples.html。

  • 列举可用的测试、计划和用户故事:
bash
tmt
  • 初始化测试管理工具的文件/项目结构:
bash
tmt init
  • 基于模板和链接创建新的测试:
bash
tmt test create {{[-t|--template]}} {{beakerlib}} --link {{verifies:issue#1234}}
  • 列出可用的测试、计划和用户故事:
bash
tmt {{test|plan|story}} ls {{pattern}}
  • 在给定的上下文中显示详细的测试元数据:
bash
tmt {{[-c|--context]}} {{arch=aarch64}} test show
  • 根据说明书验证测试管理工具文件的有效性:
bash
tmt lint
  • 使用筛选条件:
bash
tmt tests ls {{[-f|--filter]}} {{tag:foo}} {{[-f|--filter]}} {{tier:0}}
  • 显示帮助:
bash
tmt --help

专用工具与其他操作 ​

acpi(Linux) · 显示电池状态或热量信息 ​

更多信息:https://manned.org/acpi。

  • 显示电池信息:
bash
acpi
  • 显示热量(温度)信息:
bash
acpi {{[-t|--thermal]}}
  • 显示冷却设备信息:
bash
acpi {{[-c|--cooling]}}
  • 用华氏度单位显示热量(温度)信息:
bash
acpi {{[-tf|--thermal --fahrenheit]}}
  • 显示所有信息:
bash
acpi {{[-V|--everything]}}
  • 从 /proc 而非 /sys 中提取信息:
bash
acpi {{[-p|--proc]}}

archey(Linux) · 一个可以以新颖的方式显示系统信息的简单工具 ​

更多信息:https://lclarkmichalek.github.io/archey3/。

  • 显示系统信息:
bash
archey

atop(Linux) · Linux 系统和进程监控工具 ​

另请参阅:htop, top, btop, btm, glances。 更多信息:https://manned.org/atop。

  • 启动:
bash
atop
  • 启动并显示每个进程的内存消耗:
bash
atop -m
  • 启动并显示磁盘信息:
bash
atop -d
  • 启动并显示进程的完整命令行:
bash
atop -c
  • 启动并显示线程特定的资源利用信息:
bash
atop -y
  • 启动并显示每个用户的进程数量:
bash
atop -au
  • 显示交互式命令的帮助:
bash
<?>

bootctl(Linux) · 控制EFI固件启动设置并管理启动加载器 ​

另请参阅:kernel-install。 更多信息:https://www.freedesktop.org/software/systemd/man/latest/bootctl.html。

  • 显示系统固件和启动加载器的信息:
bash
bootctl status
  • 显示所有可用的启动加载器条目:
bash
bootctl list
  • 将系统固件设置为在下次启动时启动:
bash
sudo bootctl reboot-to-firmware true
  • 指定EFI系统分区(默认为/efi/,/boot/或/boot/efi):
bash
bootctl --esp-path={{/path/to/efi_system_partition/}}
  • 将systemd-boot安装到EFI系统分区:
bash
sudo bootctl install
  • 从EFI系统分区移除所有已安装的systemd-boot版本:
bash
sudo bootctl remove

cpuid(Linux) · 显示有关所有 CPU 的详细信息 ​

更多信息:https://manned.org/cpuid.1。

  • 显示所有 CPU 的信息:
bash
cpuid
  • 仅显示当前 CPU 的信息:
bash
cpuid {{[-1|--one-cpu]}}
  • 显示原始十六进制信息,不进行解码:
bash
cpuid {{[-r|--raw]}}

lscpu(Linux) · 显示 CPU 架构信息 ​

更多信息:https://manned.org/lscpu。

  • 显示所有 CPU 信息:
bash
lscpu
  • 以表格方式显示信息:
bash
lscpu {{[-e|--extended]}}
  • 仅显示表中离线 CPU 的信息:
bash
lscpu {{[-e|--extended]}} {{[-c|--offline]}}

mbw(Linux) · 内存带宽性能测试工具 ​

更多信息:https://manned.org/mbw。

  • 以 512MB 大小运行 3 次内存带宽测试:
bash
mbw -n 3 512
  • 以 512MB 大小运行 3 次内存带宽测试,仅输出统计信息,不显示平均值:
bash
mbw -n 3 -q -a 512
  • 以 512MB 大小运行 3 次内存复制测试,仅输出统计信息:
bash
mbw -n 3 -q -t{{0}} 512
  • 用 1024字节 的块运行10次内存块复制测试,分配 8192MB 内存:
bash
mbw -n 10 -q -t{{2}} -b 1024 8192
  • 持续 2048MB 大小运行内存字符串复制测试,仅输出统计信息:
bash
mbw -n 0 -t{{1}} -q 2048

poweroff(Linux) · 关闭系统 ​

另请参阅:shutdown。 更多信息:https://manned.org/poweroff。

  • 关闭系统电源:
bash
poweroff
  • 停止系统(等同于 halt):
bash
poweroff --halt
  • 重启系统(等同于 reboot):
bash
poweroff --reboot
  • 立即关机,不联系系统管理器:
bash
poweroff {{[-f|--force]}}
  • 仅写入 wtmp 关机日志条目而不关闭系统:
bash
poweroff {{[-w|--wtmp-only]}}

reboot(Linux) · 重新启动系统 ​

更多信息:https://manned.org/reboot.8。

  • 重启系统:
bash
reboot
  • 关闭系统(等同于 poweroff):
bash
reboot {{[-p|--poweroff]}}
  • 停止系统(终止所有进程并关闭 CPU,等同于 halt):
bash
reboot --halt
  • 立即重启,而无需正常关闭:
bash
reboot {{[-f|--force]}}
  • 仅写入 wtmp 关机日志条目而不重启系统:
bash
reboot {{[-w|--wtmp-only]}}

systemctl(Linux) · 控制 systemd 系统和服务管理器 ​

更多信息:https://www.freedesktop.org/software/systemd/man/latest/systemctl.html。

  • 显示系统管理器概况及单元进程树;运行服务列表另用 systemctl list-units --type=service --state=running:
bash
systemctl status
  • 列出失败的单元:
bash
systemctl --failed
  • 启动/停止/重启/重新加载/显示服务的状态:
bash
systemctl {{start|stop|restart|reload|status}} {{单元}}
  • 启用/禁用开机时启动的单元:
bash
systemctl {{enable|disable}} {{单元}}
  • 重新加载 systemd,扫描新的或更改的单元:
bash
systemctl daemon-reload
  • 检查单元是否激活/启用/失败:
bash
systemctl {{is-active|is-enabled|is-failed}} {{单元}}
  • 按运行/失败状态过滤列出所有服务/套接字/自动挂载单元:
bash
systemctl list-units {{[-t|--type]}} {{service|socket|automount}} --state {{failed|running}}
  • 显示单元文件的内容和绝对路径:
bash
systemctl cat {{单元}}

示例整理自 tldr-pages,作者为 tldr-pages team and contributors,遵循 CC BY 4.0。

继续阅读