【linux端cursor CLI常用命令】
记录linux端安装cursor工具,使用cursor助手辅助创建项目、管理部署项目
📋 核心命令列表
🔐 认证相关
1 │# 查看登录状态
2 │cursor-agent status
3 │# 查看当前认账用户信息
4 │cursor-agent whoami
6 │# 登录 Cursor 账号
7 │cursor-agent login
9 │# 登出
10 │cursor-agent logout
🤖 AI 助手命令
1 │# 启动交互式 AI 助手
2 │cursor-agent
4 │# 直接提问(非交互式)
5 │cursor-agent “帮我写一个 Python 函数”
7 │# 使用特定模型
8 │cursor-agent --model gpt-5 “解释这个代码”
10 │# 后台模式启动
11 │cursor-agent --background
💬 聊天管理
1 │# 创建新聊天
2 │cursor-agent create-chat
4 │# 恢复最新聊天
5 │cursor-agent resume
7 │# 恢复指定聊天
8 │cursor-agent resume [chatId]
10 │# 列出聊天记录
11 │cursor-agent ls
🛠️ 脚本和自动化
1 │# 打印模式(用于脚本)
2 │cursor-agent --print “生成一个 bash 脚本”
4 │# JSON 输出格式
5 │cursor-agent --print --output-format json “分析这个文件”
7 │# 流式输出
8 │cursor-agent --print --output-format stream-json --stream-partial-output “长文本生成”
⚙️ 配置和工具
1 │# 更新 Cursor Agent
2 │cursor-agent update
4 │# 安装 shell 集成
5 │cursor-agent install-shell-integration
7 │# 卸载 shell 集成
8 │cursor-agent uninstall-shell-integration
10 │# MCP 服务器管理
11 │cursor-agent mcp
13 │# 沙盒配置
14 │cursor-agent sandbox
🔧 高级选项
1 │# 强制允许命令
2 │cursor-agent --force “执行系统命令”
4 │# 自动批准 MCP 服务器
5 │cursor-agent --approve-mcps --print “使用 MCP 工具”
7 │# 启用浏览器自动化
8 │cursor-agent --browser “自动化网页操作”
10 │# 设置 API 密钥
11 │cursor-agent --api-key YOUR_API_KEY “命令”
💡 实用示例
- 代码生成和修改
1 │# 生成 Python 代码
2 │cursor-agent “写一个 Flask API 服务器”
4 │# 修改现有文件
5 │cursor-agent “优化这个 Python 脚本的性能” < script.py - 文件操作
1 │# 分析项目结构
2 │cursor-agent “分析这个项目的架构” --print
4 │# 生成文档
5 │cursor-agent “为这个项目生成 README.md” --print > README.md - 系统管理
1 │# 系统诊断
2 │cursor-agent “检查系统性能问题”
4 │# 配置管理
5 │cursor-agent “优化 Nginx 配置” - 开发工作流
1 │# 代码审查
2 │cursor-agent “审查这个代码的质量和安全性”
4 │# 测试生成
5 │cursor-agent “为这个函数生成单元测试”
当服务端存在普通用户sec和root用户时,在root设置cursor-agent配置(已有会话token)后,在关闭xshell连接后重新连接服务器如何持久化token(免除密码登录)
方案A(系统级 PATH,最省心):
- 找到实际安装路径(先以 root 登录后执行):
假设输出为su - root which cursor-agent || find /root -type f -name cursor-agent 2>/dev/null/root/.local/bin/cursor-agent - 做系统级软链(所有用户都能找到):
验证:su - root ln -sf /root/.local/bin/cursor-agent /usr/local/bin/cursor-agent
如果你之后用exit # 退出到普通用户 su - root cursor-agent --versionsudo执行命令仍提示找不到,再检查sudo的 secure_path(见下文“sudo 情况”)。
