Skip to content

附录 A · 命令速查

都是 只读观察 向命令(删文件类不在此列)。macOS 为主,多数概念 Linux 通用。

作者:曹宇春


系统与负载

bash
sw_vers                 # macOS 版本
uname -a                # 内核信息
uptime                  # 开机时长 + 负载 1/5/15 分钟
sysctl -n hw.ncpu       # 逻辑核数
sysctl -n machdep.cpu.brand_string

进程

bash
ps aux | head -20
ps aux | sort -nrk 3 | head -10   # 按 CPU
ps aux | sort -nrk 4 | head -10   # 按内存 %
top -l 1 -n 10 -stats pid,command,cpu,mem
kill <PID>              # 礼貌退出(SIGTERM)
# kill -9 <PID>         # 强杀(慎用)

内存

bash
memory_pressure
vm_stat | head -20

关注:空闲页、compressor、Swapins/Swapouts。

磁盘

bash
df -h
df -i
du -sh ~/Documents ~/Downloads ~/Library 2>/dev/null

网络与端口

bash
lsof -i :3000
lsof -i -n | head -20
netstat -an | grep ESTABLISHED | head -10

文件权限

bash
ls -l <>
id

父子进程

bash
echo $$
ps -p $$ -o pid,ppid,command

对照本课

命令族相关课
ps / top / uptime02、04
vm_stat / memory_pressure03
df / du05
lsof / netstat06
ls -l / id09

© 曹宇春

© 曹宇春 · 个人学习整理,欢迎交流