gdcli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGoogle Drive CLI
Google Drive CLI
Command-line interface for Google Drive operations.
用于Google Drive操作的命令行界面工具。
Installation
安装
bash
npm install -g @mariozechner/gdclibash
npm install -g @mariozechner/gdcliSetup
配置
Google Cloud Console (one-time)
Google Cloud 控制台(一次性操作)
- Create a new project (or select existing)
- Enable the Google Drive API
- Set app name in OAuth branding
- Add test users (all Gmail addresses you want to use)
- Create OAuth client:
- Click "Create Client"
- Application type: "Desktop app"
- Download the JSON file
- 创建新项目(或选择现有项目)
- 启用Google Drive API
- 在OAuth品牌设置中设置应用名称
- 添加测试用户(所有你想使用的Gmail地址)
- 创建OAuth客户端:
- 点击“创建客户端”
- 应用类型:“桌面应用”
- 下载JSON文件
Configure gdcli
配置gdcli
First check if already configured:
bash
gdcli accounts listIf no accounts, guide the user through setup:
- Ask if they have a Google Cloud project with Drive API enabled
- If not, walk them through the Google Cloud Console steps above
- Have them download the OAuth credentials JSON
- Run:
gdcli accounts credentials ~/path/to/credentials.json - Run: (use
gdcli accounts add <email>for browserless OAuth)--manual
首先检查是否已完成配置:
bash
gdcli accounts list如果没有添加任何账户,按照以下步骤引导完成设置:
- 询问用户是否已拥有启用Drive API的Google Cloud项目
- 如果没有,引导用户完成上述Google Cloud控制台的操作步骤
- 让用户下载OAuth凭证JSON文件
- 运行:
gdcli accounts credentials ~/path/to/credentials.json - 运行:(使用
gdcli accounts add <email>参数进行无浏览器OAuth验证)--manual
Usage
使用方法
Run for full command reference.
gdcli --helpCommon operations:
- - List files/folders
gdcli <email> ls [folderId] - - List with Drive query filter
gdcli <email> ls --query "<query>" - - Full-text content search
gdcli <email> search "<text>" - - Download a file
gdcli <email> download <fileId> [destPath] - - Upload a file
gdcli <email> upload <localPath> [--folder <folderId>] - - Create a folder
gdcli <email> mkdir <name> - - Share publicly
gdcli <email> share <fileId> --anyone
运行查看完整命令参考。
gdcli --help常见操作:
- - 列出文件/文件夹
gdcli <email> ls [folderId] - - 使用Drive查询过滤器列出内容
gdcli <email> ls --query "<query>" - - 全文内容搜索
gdcli <email> search "<text>" - - 下载文件
gdcli <email> download <fileId> [destPath] - - 上传文件
gdcli <email> upload <localPath> [--folder <folderId>] - - 创建文件夹
gdcli <email> mkdir <name> - - 公开共享
gdcli <email> share <fileId> --anyone
Search
搜索
Two different commands:
- - Searches inside file contents (fullText)
search "<text>" - - Filters by metadata (name, type, date, etc.)
ls --query "<query>"
Use for filename searches!
ls --query两种不同的命令:
- - 搜索文件内容(全文检索)
search "<text>" - - 按元数据筛选(名称、类型、日期等)
ls --query "<query>"
文件名搜索请使用!
ls --queryQuery Syntax (for ls --query)
查询语法(适用于ls --query)
Format: . Combine with /, group with .
field operator valueandor()Operators: , , , , , ,
=!=contains<><=>=Examples:
bash
undefined格式:。使用/组合条件,用分组。
字段 操作符 值andor()操作符: , , , , , ,
=!=contains<><=>=示例:
bash
undefinedBy filename
按文件名
ls --query "name = 'report.pdf'" # exact match
ls --query "name contains 'IMG'" # prefix match
ls --query "name = 'report.pdf'" # 精确匹配
ls --query "name contains 'IMG'" # 前缀匹配
By type
按类型
ls --query "mimeType = 'application/pdf'"
ls --query "mimeType contains 'image/'"
ls --query "mimeType = 'application/vnd.google-apps.folder'" # folders
ls --query "mimeType = 'application/pdf'"
ls --query "mimeType contains 'image/'"
ls --query "mimeType = 'application/vnd.google-apps.folder'" # 文件夹
By date
按日期
ls --query "modifiedTime > '2024-01-01'"
ls --query "modifiedTime > '2024-01-01'"
By owner/sharing
按所有者/共享状态
ls --query "'me' in owners"
ls --query "sharedWithMe"
ls --query "'me' in owners"
ls --query "sharedWithMe"
Exclude trash
排除已删除文件
ls --query "trashed = false"
ls --query "trashed = false"
Combined
组合条件
ls --query "name contains 'report' and mimeType = 'application/pdf'"
Ref: https://developers.google.com/drive/api/guides/ref-search-termsls --query "name contains 'report' and mimeType = 'application/pdf'"
参考文档:https://developers.google.com/drive/api/guides/ref-search-termsData Storage
数据存储
- - OAuth client credentials
~/.gdcli/credentials.json - - Account tokens
~/.gdcli/accounts.json - - Default download location
~/.gdcli/downloads/
- - OAuth客户端凭证
~/.gdcli/credentials.json - - 账户令牌
~/.gdcli/accounts.json - - 默认下载路径
~/.gdcli/downloads/