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
累計下載
4490
星標
4
全站排名
#2,149
全站前 43% · 「運維安全」前 44%
平台累計安裝累計下載星標評論
ClawHub ↗13444804-
SkillHub ↗18544903—

各平台的計數口徑不同,統計時間不一致。

這個技能是做什麼的

主文涵蓋 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 服務狀態的步驟

月度資料趨勢

累計下載4490
2366350746472026-03 · 累計下載 25232026-05 · 累計下載 33482026-06 · 累計下載 35442026-07 · 累計下載 40032026-08 · 累計下載 42682026-09 · 累計下載 449026-0326-09
星標4
2342026-03 · 星標 22026-05 · 星標 32026-06 · 星標 32026-07 · 星標 32026-08 · 星標 42026-09 · 星標 426-0326-09

2026-09 起統計方法調整:同名技能按作者分別統計,並覆蓋全部技能。圖中虛線為調整前的月份,與之後的資料不直接比較,也不計算跨越調整的增長。

月份累計下載環比星標
2026-094490—4
2026-084268+6.6%4
2026-074003+13.0%3
2026-063544+5.9%3
2026-053348—3
2026-032523—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),按月更新。口徑說明見資料方法。