这条路径按依赖顺序分四阶段,每阶段建议留 2–3 小时。先读、再做、后测:按阅读顺序看页面,动手任务在测试账户或一次性 macOS 虚拟机里完成,过关问题答不上来就回到对应页面。
不要从背快捷键开始。macOS 的命令行是 BSD 用户态加 launchd、SIP、TCC 和 APFS 的组合;先建立“命令 → 系统对象 → 权限边界”的对应关系,再进入开发工具链。
% mkdir -p ~/macos-lab; printf 'alpha\nbeta\n' > ~/macos-lab/access.log
% find ~/macos-lab -type f -print0 | xargs -0 stat -f '%N %z bytes'
% xattr -l ~/macos-lab/access.log; chmod 640 ~/macos-lab/access.log; ls -le ~/macos-lab/access.log
% mdfind -onlyin ~/macos-lab access; open -R ~/macos-lab/access.log
find 没有 -printf 时用 -exec stat -f 或 xargs 替代;理解 rm 不进废纸篓;能区分模式位、ACL 和 com.apple.quarantine 这类扩展属性;知道 mdfind 依赖 Spotlight 索引。% sw_vers; uname -m; sysctl -n hw.ncpu hw.memsize
% ps -Ao pid,ppid,%cpu,%mem,comm -r | head
% launchctl print gui/$(id -u) | head -30; launchctl list | head
% pmset -g; tmutil listlocalsnapshots /; sudo launchctl print system | head -20; csrutil status
launchctl load/unload 与 bootstrap/bootout 的关系;能解释 SIP 保护哪些路径;知道本地快照不是异地备份。% ifconfig en0 | grep -E 'inet |status'; netstat -anv | grep LISTEN | head
% lsof -nP -iTCP -sTCP:LISTEN | head; dscacheutil -q host -a name example.com
% dig example.com +short; curl -I --max-time 5 https://example.com
% sudo tcpdump -ni en0 -c 5 'tcp port 443'; ssh -V; rsync -av --dry-run ~/macos-lab/ /tmp/macos-lab-backup/
netstat、lsof、tcpdump 各自看哪一层;知道先用 ifconfig -l 确认接口名(Wi-Fi 不一定是 en0);能说清 DNS 缓存刷新要同时用 dscacheutil -flushcache 和 killall -HUP mDNSResponder;知道 Gatekeeper 首启检查依赖 quarantine 标记。% xcode-select -p; xcrun --find clang; brew --prefix; brew doctor
% diskutil list; diskutil info / | grep -E 'File System|APFS'
% hdiutil create -size 64m -fs APFS -volname Lab /tmp/lab.dmg; hdiutil attach /tmp/lab.dmg
% hdiutil detach /Volumes/Lab; tmutil listbackups; defaults export com.apple.dock /tmp/dock-backup.plist
/opt/homebrew 与 /usr/local 分别对应哪种架构;知道 diskutil list 的标识符在擦除前必须核对;能解释 APFS 容器共享空间;知道修改 defaults 前先导出备份。find 没有 -printf,怎样输出文件名和大小?/usr/local/bin/brew 找不到,如何判断并修正?find ... -exec stat -f '%N %z' {} +,或 -print0 | xargs -0 stat -f '%N %z';BSD stat 的格式符和 GNU 不同。/Library/LaunchDaemons,由 system 域以 root 启动;它没有 GUI 会话,不能依赖用户登录或弹窗。uname -m 和 brew --prefix 确认;Apple Silicon 原生 brew 在 /opt/homebrew,把 /opt/homebrew/bin 放到 PATH 前面,避免混用 x86 brew。
小程序版
微信扫码,随时查命令