《OpenClaw从入门到精通》书中命令行汇总
说明:
•
本文按书稿章节顺序整理,仅收录需要读者在终端、Shell、TUI 或相关命令行环境中输入的命令。
•
配置键名、JSON 片段、版本号示例、界面选项、自然语言提示词不在本文收录范围内。
•
同一小节内的重复命令已去重;不同章节中的重复命令按原章节保留。
第2章 从零安装:本机配置到首次对话
2.2 环境检查与安装
2.2.1 Node.js 检查与安装
node --version
brew install node
brew upgrade node
winget install OpenJS.NodeJS.LTS
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs
2.2.2 安装OpenClaw
npm install -g openclaw@latest
sudo npm install -g openclaw@latest
2.2.3 验证安装结果
openclaw --version
2.3 运行初始化向导
2.3.1 启动向导
openclaw onboard --install-daemon
openclaw config get tools.profile
openclaw config set tools.profile "coding"
sudo loginctl enable-linger $USER
2.3.3 daemon安装失败问题分析和解决方案
sudo loginctl enable-linger $USER
systemctl --user status
openclaw onboard --skip-daemon
openclaw health
2.3.4 记录关键信息
openclaw status
2.4 常见问题排查
2.4.1 command not found错误
npm prefix -g
echo $PATH | grep $(npm prefix -g)
# zsh(macOS 默认)
echo 'export PATH="$(npm prefix -g)/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
# bash
echo 'export PATH="$(npm prefix -g)/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
2.4.2 权限问题
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
npm install -g openclaw@latest
2.4.3 端口被占用
openclaw gateway run --port 18790
2.4.4 网络问题
npm install -g openclaw
npm config set registry https://registry.npmmirror.com
npm install -g openclaw@latest
npm install -g openclaw --proxy http://proxy.company.com:8080
2.4.5 401/403错误
openclaw config get models
openclaw onboard
2.4.6 界面正常但Agent无响应
openclaw status
openclaw logs
openclaw doctor
openclaw gateway stop
openclaw gateway start
2.4.7 Windows用户的特别说明
wsl --install
2.5 动手试试
openclaw doctor
第3章 协作关系、处理流程与Workspace边界
3.4 动手试试
openclaw status
openclaw agents list
第4章 接入飞书:从单机版到在线协作版的跨越
4.2 4个手动完成环节
4.2.2 确认环境并完成飞书Channel 配置
openclaw channels list
openclaw channels add
4.2.3 启动 Gateway 并完成长连接与消息事件订阅
openclaw gateway start
4.2.4 触发配对、管理员审批与私聊验证
openclaw pairing approve feishu <配对码>
openclaw pairing approve feishu QX3YQT4T
4.7 常见问题排障
4.7.1 长连接订阅失败
openclaw status
4.7.2 消息无响应
openclaw status
openclaw channels list
openclaw pairing list feishu
openclaw logs --follow
4.7.3 机器人出现非预期回复
openclaw config set channels.feishu.enabled false --json
openclaw config set channels.feishu.enabled true --json
第5章 配置管理:文件、目录与环境变量
5.1 目录结构与日志
5.1.2 日志
openclaw logs --follow
openclaw logs --limit 100
openclaw logs | grep skill-name
5.2 配置文件在哪里
5.2.2 如何查看和编辑
openclaw config get gateway.port
openclaw config set gateway.port 18790 --json
openclaw config unset gateway.port
openclaw configure
cp ~/.openclaw/openclaw.json ~/.openclaw/openclaw.json.backup
5.3 配置的分层与优先级
5.3.1 实例演示
openclaw gateway run --port 18790
5.3.2 查看当前生效的配置
openclaw configure
openclaw config get gateway.port
openclaw config get agents.defaults.model.primary
openclaw doctor
5.4 环境变量与敏感信息管理
5.4.1 不要做的事
git add ~/.openclaw/openclaw.json
git commit -m "add config"
5.4.2 推荐做法
# 临时(当前终端会话有效)
export KIMI_API_KEY="sk-xxxxxxxxxxxxx"
openclaw gateway start
# 持久(写入 shell 配置文件)
# macOS/Linux 写入 ~/.zshrc 或 ~/.bashrc
echo 'export KIMI_API_KEY="sk-xxxxxxxxxxxxx"' >> ~/.zshrc
source ~/.zshrc
5.4.3 泄露应对方法
openclaw configure
openclaw secrets configure
openclaw gateway restart
5.6 配置变更的验证方式
5.6.1 标准验证流程
openclaw config set gateway.port 18790 --json
openclaw gateway restart
openclaw status
openclaw doctor
openclaw models status
openclaw channels status --probe
5.6.2 配置出错时快速回滚
cp ~/.openclaw/openclaw.json ~/.openclaw/openclaw.json.backup
cp ~/.openclaw/openclaw.json.backup ~/.openclaw/openclaw.json
openclaw gateway restart
openclaw doctor
第6章 模型选择、配置与切换
6.2 最小可用模型的接入
6.2.1 KIMI
openclaw onboard
openclaw models set kimi-coding/k2p5
6.2.2 MiniMax
openclaw models set minimax/MiniMax-M2.5
6.2.3 GLM
openclaw models set zai/glm-5
6.3 主/备模型设置与动态切换
6.3.2 动态切换模型
/model
第7章 安全配置:权限、审批与凭证管理
7.2 审批策略与流程
7.2.2 审批流程
openclaw approvals get
openclaw approvals set --file ./exec-approvals.json
openclaw approvals allowlist add "~/Projects/**/bin/rg"
openclaw approvals allowlist remove "~/Projects/**/bin/rg"
7.4 凭证管理进阶
7.4.3 使用SecretRef
openclaw secrets audit --check
openclaw secrets configure
openclaw secrets apply --from /tmp/openclaw-secrets-plan.json --dry-run
openclaw secrets reload
第8章 工具与Skills入门与应用
8.6 Skills注册、安装与管理
8.6.1 安装ClawHub CLI
npm install -g clawhub
pnpm add -g clawhub
clawhub login
clawhub whoami
8.6.2 搜索Skills
clawhub search 日报
clawhub install daily-report
clawhub install daily-report --version 1.2.0
clawhub install daily-report --force
8.6.3 更新与同步
clawhub update daily-report
clawhub update --all
clawhub list
clawhub sync --dry-run
clawhub sync --all
8.6.4 版本管理
openclaw skills list
openclaw skills info daily-report
clawhub install daily-report --version 1.1.0
8.7 Skills加载优先级与运行期配置
8.7.2 skills.entries运行期配置
# 查看当前配置
openclaw config get skills.entries
8.7.3 上线前可用性检查
openclaw skills list
openclaw skills list --eligible
openclaw skills check
8.7.4 可用性门控与生效规则
# 查看单个 Skills 详情(查看权限声明和依赖)
openclaw skills info daily-report
8.8 编写第一个Skills:日报生成器
8.8.1 创建目录并编写SKILL.md
mkdir -p ~/.openclaw/workspace/skills/daily-report
cd ~/.openclaw/workspace/skills/daily-report
8.8.2 验证与测试Skills
openclaw skills check
openclaw skills info daily-report
/skill daily-report
8.9 发布与维护
8.9.1 准备并发布到ClawHub
clawhub login
cd ~/.openclaw/workspace/skills/daily-report
clawhub publish
8.9.2 后续维护
clawhub publish --version 1.1.0
clawhub sync
8.9.3 让Skills稳定可靠
openclaw config get tools
openclaw skills check
第9章 运维与问题排查
9.1 多Workspace、多Agent与运行环境的维护
9.1.1 多Workspace与多Agent
openclaw setup --workspace
# 创建新 Workspace
mkdir -p ~/workspaces/project-a
openclaw setup --workspace ~/workspaces/project-a
9.1.3 服务维护策略
openclaw gateway install
openclaw gateway status
# 1. 允许当前用户在退出登录后继续保留 systemd 用户服务
sudo loginctl enable-linger $USER
# 2. 重新写入并安装用户服务
openclaw gateway install --force
# 3. 检查用户服务状态
systemctl --user status openclaw-gateway.service
systemctl --user is-enabled openclaw-gateway.service
openclaw gateway install --force
sudo systemctl daemon-reload
sudo systemctl enable --now openclaw-gateway.service
sudo systemctl status openclaw-gateway.service
sudo systemctl restart openclaw-gateway.service
sudo systemctl stop openclaw-gateway.service
sudo journalctl -u openclaw-gateway.service -f
openclaw gateway stop
cp -r ~/backups/openclaw-20260228/config ~/.openclaw/
cp -r ~/backups/openclaw-20260228/skills ~/.openclaw/workspace/
cp -r ~/backups/openclaw-20260228/data ~/.openclaw/
openclaw gateway start
openclaw --version
npm view openclaw version
npm install -g openclaw@latest
openclaw doctor
# 如果新版本有问题,回退到本书对应版本
npm install -g openclaw@2026.3.2
9.4 Channel的维护与排障
9.4.1 Telegram
openclaw channels add
openclaw gateway start
9.4.3 Slack
openclaw channels add
openclaw gateway start
9.4.6 插件Channel的最小运维动作
openclaw plugins list
openclaw plugins install <path|.tgz|npm-spec>
openclaw plugins enable <id>
openclaw plugins list --json
openclaw channels add
9.5 动手试试
openclaw doctor
openclaw skills list
openclaw channels status --probe
附录A CLI命令速查
A.1 最常用的“救命八连”
openclaw --version
openclaw status
openclaw doctor
openclaw logs --follow
openclaw gateway status
openclaw channels status --probe
openclaw sessions --json
openclaw health
A.2 安装、升级与初始化
curl -fsSL https://openclaw.ai/install.sh | bash
npm i -g openclaw@latest
pnpm add -g openclaw@latest
openclaw setup
openclaw onboard
openclaw onboard --install-daemon
openclaw onboard --skip-daemon
openclaw update
A.3 Gateway 网关管理
openclaw gateway
openclaw gateway run
openclaw gateway install
openclaw gateway start
openclaw gateway stop
openclaw gateway restart
openclaw gateway status
openclaw gateway probe
openclaw gateway discover
openclaw gateway call status
A.4 配置与模型
openclaw configure
openclaw config file
openclaw config get <path>
openclaw config set <path> <value>
openclaw config unset <path>
openclaw config validate
openclaw models list
openclaw models status
openclaw models set <provider/model>
A.5 Channel 与配对
openclaw channels list
openclaw channels add
openclaw channels remove --channel <name>
openclaw channels login --channel whatsapp
openclaw channels logout --channel whatsapp
openclaw channels status --probe
openclaw pairing list [channel]
openclaw pairing approve <channel> <code>
A.6 Skills、插件与多 Agent
openclaw skills list
openclaw skills list --eligible
openclaw skills info <name>
openclaw skills check
clawhub search <keyword>
clawhub install <slug>
clawhub update --all
openclaw plugins list
openclaw plugins install <path|.tgz|npm-spec>
openclaw plugins enable <id>
openclaw plugins disable <id>
openclaw agents bindings
openclaw agents list
openclaw agents bind --agent <id> --bind <channel[:account]>
openclaw agents unbind --agent <id> --bind <channel[:account]>
openclaw agents add [name] --workspace <dir>
openclaw agents delete <id>
A.7 安全与审批
openclaw security audit
openclaw security audit --deep
openclaw secrets audit --check
openclaw secrets configure
openclaw secrets apply --from <plan.json> --dry-run
openclaw secrets reload
openclaw approvals get
openclaw approvals set --file <jsonFile>
openclaw approvals allowlist add <path>
openclaw approvals allowlist remove <path>
A.8 会话与重置(慎用)
openclaw sessions
openclaw sessions --active 120
openclaw sessions --json
openclaw reset --dry-run
openclaw reset --scope config+creds+sessions --yes --non-interactive
附录B 配置文件完整示例
B.5 修改配置的稳妥流程(建议优先阅读)
cp ~/.openclaw/openclaw.json ~/.openclaw/openclaw.json.backup
openclaw gateway restart
openclaw status
openclaw gateway status
B.6 回滚配置(出现问题时使用)
cp ~/.openclaw/openclaw.json.backup ~/.openclaw/openclaw.json
openclaw gateway restart