Iván

macOS

运维安全v1.0.0
作者:Iván更新于 2026-05-17macos@clawhub_ivangdavila/macos
服务器运维DevOps#System Administration

据 AlphaMoat 统计,截至 2026-09,macOS 累计下载 4,490 次、获 4 个星标,在全部 5,078 个 AI 技能中排名第 2,149 位,在「运维安全」分类(264 个)中排名第 115 位。

累计安装
185
累计下载
4,490
星标
4
全站排名
#2,149
全站前 43% · 「运维安全」前 44%
平台累计安装累计下载星标评论
ClawHub ↗1344,4804-
SkillHub ↗1854,4903—

各平台的计数口径不同,统计时间不一致。

这个技能是做什么的

主文涵盖 BSD 与 GNU 命令差异、Apple Silicon 和 Intel 的 Homebrew 路径、Keychain、launchd 及隐私权限等主题,适合处理 macOS 环境下的运维问题。

资料发布于 2026-10-27

可以用来做什么

  • 排查 macOS 与 Linux 命令行为差异
  • 了解 launchd、Keychain 或隐私权限的操作要点

什么时候用

  • 需要在 macOS 上编写或排查 shell 命令时
  • 需要了解 macOS 自动化和系统管理方式时

示例提示词

以下是根据技能文档生成的示例,不代表实际运行结果。

解释 macOS 下 sed 与 GNU sed 的差异
整理在 macOS 上检查 launchd 服务状态的步骤

月度数据趋势

累计下载4,490
2,3663,5074,6472026-03 · 累计下载 2,5232026-05 · 累计下载 3,3482026-06 · 累计下载 3,5442026-07 · 累计下载 4,0032026-08 · 累计下载 4,2682026-09 · 累计下载 4,49026-0326-09
星标4
2342026-03 · 星标 22026-05 · 星标 32026-06 · 星标 32026-07 · 星标 32026-08 · 星标 42026-09 · 星标 426-0326-09

2026-09 起统计方法调整:同名技能按作者分别统计,并覆盖全部技能。图中虚线为调整前的月份,与之后的数据不直接比较,也不计算跨越调整的增长。

月份累计下载环比星标
2026-094,490—4
2026-084,268+6.6%4
2026-074,003+13.0%3
2026-063,544+5.9%3
2026-053,348—3
2026-032,523—2

SKILL.md 原文

以下是作者发布的原始文件,按纯文本显示,本站未做修改或审核;其中的链接不可点击,命令请核实后再运行。抓取于 2026-10-23。

5.6 KB · ClawHub v1.0.0
---
name: macOS
description: macOS system administration, command-line differences from Linux, and automation best practices.
metadata:
  category: system
  skills: ["macos", "osx", "apple", "darwin", "terminal"]
---

## BSD vs GNU Commands
展开全部(共 122 行)
- `sed -i` requires extension argument: `sed -i '' 's/a/b/' file` — empty string for no backup, Linux doesn't need it
- `find` doesn't support `-printf` — use `-exec stat` or `xargs` with `stat -f` instead
- `date` uses different format flags: `date -j -f '%Y-%m-%d' '2024-01-15' '+%s'` — `-j` prevents setting time
- `grep -P` (Perl regex) doesn't exist — use `grep -E` (extended) or install `ggrep` via Homebrew
- `xargs` defaults to `/usr/bin/echo` not the command — always specify the command explicitly
- `readlink -f` doesn't exist — use `realpath` or `python3 -c "import os; print(os.path.realpath('path'))"`

## Homebrew Paths

- Apple Silicon: `/opt/homebrew/bin`, `/opt/homebrew/lib`
- Intel: `/usr/local/bin`, `/usr/local/lib`
- Check architecture: `uname -m` returns `arm64` or `x86_64`
- Homebrew doesn't add to PATH automatically — check `~/.zprofile` for eval line
- Running x86 binaries: `arch -x86_64 /bin/bash` then install/run Intel-only tools

## Keychain (Secrets)

- Store: `security add-generic-password -a "$USER" -s "service_name" -w "secret_value" -U`
- Retrieve: `security find-generic-password -a "$USER" -s "service_name" -w`
- `-U` flag updates if exists — without it, duplicate entries error
- Keychain prompts for access on first use — authorize permanently for automation
- Delete: `security delete-generic-password -a "$USER" -s "service_name"`

## launchd (Services)

- User agents: `~/Library/LaunchAgents/` — runs as user when logged in
- System daemons: `/Library/LaunchDaemons/` — runs at boot as root
- Load: `launchctl load -w ~/Library/LaunchAgents/com.example.plist`
- Unload before editing: `launchctl unload` — edits to loaded plists are ignored
- Check errors: `launchctl list | grep service_name` then `launchctl error <exit_code>`
- Logs: `log show --predicate 'subsystem == "com.example"' --last 1h`

## Privacy Permissions (TCC)

- Automation scripts fail silently without Full Disk Access or Automation permissions
- Grant in System Settings → Privacy & Security → corresponding category
- Terminal and iTerm need separate permissions — granting to one doesn't grant to other
- `tccutil reset` clears permissions: `tccutil reset AppleEvents` for Automation
- Check granted permissions: `sqlite3 ~/Library/Application\ Support/com.apple.TCC/TCC.db "SELECT * FROM access"`

## defaults (Preferences)

- Read: `defaults read com.apple.finder AppleShowAllFiles`
- Write: `defaults write com.apple.finder AppleShowAllFiles -bool true`
- Delete: `defaults delete com.apple.finder AppleShowAllFiles`
- Restart app after changing: `killall Finder`
- Find app bundle ID: `osascript -e 'id of app "App Name"'`
- Export all: `defaults export com.apple.finder -` outputs XML

## File Operations

- `ditto` preserves resource forks and metadata — use instead of `cp` for app bundles
- Create DMG: `hdiutil create -volname "Name" -srcfolder ./folder -format UDZO output.dmg`
- Mount DMG: `hdiutil attach image.dmg` — returns mount point path
- Unmount: `hdiutil detach /Volumes/Name`
- Extended attributes: `xattr -l file` to list, `xattr -c file` to clear all
- Quarantine removal: `xattr -d com.apple.quarantine app.app`

## Clipboard

- Copy to clipboard: `echo "text" | pbcopy`
- Paste from clipboard: `pbpaste`
- Copy file contents: `pbcopy < file.txt`
- Preserve RTF: `pbpaste -Prefer rtf`
- Clipboard works in SSH sessions to local machine — useful for remote file copying

## Screenshots and Screen

- Screenshot region to file: `screencapture -i output.png`
- Screenshot window: `screencapture -w output.png`
- Screenshot to clipboard: `screencapture -c`
- Headless (no UI): `screencapture -x` — suppresses sound and cursor
- Screen recording requires Screen Recording permission in Privacy settings

## Process Management

- Prevent sleep: `caffeinate -i command` — keeps system awake while command runs
- Prevent sleep with timeout: `caffeinate -t 3600` — 1 hour
- Check why not sleeping: `pmset -g assertions`
- Power settings: `pmset -g` to view, `sudo pmset -a sleep 0` to disable sleep
- Current app in focus: `osascript -e 'tell application "System Events" to get name of first process whose frontmost is true'`

## Network

- List interfaces: `networksetup -listallhardwareports`
- Get IP: `ipconfig getifaddr en0` (Wi-Fi usually en0 on laptops)
- DNS servers: `scutil --dns | grep nameserver`
- Flush DNS: `sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder`
- Proxy settings: `networksetup -getwebproxy "Wi-Fi"`

## System Integrity Protection

- Check status: `csrutil status`
- Disable (Recovery Mode only): `csrutil disable` — not recommended for production
- Protected paths: `/System`, `/usr` (except `/usr/local`), `/sbin`, `/bin`
- Can't modify these even as root — design your automations around this

## Logs

- Stream live: `log stream --predicate 'process == "processname"'`
- Search recent: `log show --last 1h --predicate 'eventMessage contains "error"'`
- Subsystem filter: `log show --predicate 'subsystem == "com.apple.example"'`
- Save to file: `log collect --output ./logs.logarchive` — opens in Console.app

## Automation Tips

- Open URL: `open "https://example.com"` — uses default browser
- Open app: `open -a "Safari"` — by name, not path
- Open file with specific app: `open -a "TextEdit" file.txt`
- Run AppleScript: `osascript -e 'tell application "Finder" to get name of home'`
- Spotlight search: `mdfind "kMDItemDisplayName == 'filename.txt'"` — faster than find for indexed files

「运维安全」分类下的热门技能

Iván 的其他技能

数据月份:2026-09 · 下载/星标/安装数聚合自公开技能注册库(ClawHub、SkillHub),按月更新。口径说明见数据方法。