命令行工具

tfile 让你在终端处理文件,适合脚本、备份和 AI Agent。它用 API 令牌登录,能做的事以令牌和你的账号权限为限。

本页内容
  1. 安装
  2. 登录
  3. 指定文件和文件夹
  4. 命令
  5. 安全地更改
  6. 输出和退出码
  7. 配置
  8. 单用户模式

安装

每个版本都附带各系统的程序。下载与你系统相符的文件:

系统文件
Linux (x86-64)tfile-<version>-linux-amd64
Linux (ARM64)tfile-<version>-linux-arm64
macOS (Apple silicon)tfile-<version>-macos-arm64
macOS (Intel)tfile-<version>-macos-amd64
Windows (x86-64)tfile-<version>-windows-amd64.exe

在 Linux 上先校验下载的文件,设为可执行,再放到终端能找到的位置。macOS 请改用 shasum -a 256 -c --ignore-missing SHA256SUMS 校验。

sha256sum -c --ignore-missing SHA256SUMS
chmod +x tfile-1.5.0-linux-amd64
sudo mv tfile-1.5.0-linux-amd64 /usr/local/bin/tfile
tfile --version

在 Windows 上,把文件改名为 tfile.exe,放到 PATH 里的文件夹。

所有程序都由 GitHub Actions 构建,可以验证来源:

gh attestation verify tfile-1.5.0-linux-amd64 -R ThirtyFile/ThirtyFile
这些程序没有 macOS 或 Windows 的代码签名。macOS 会阻止首次运行:校验下载文件后运行 xattr -d com.apple.quarantine tfile。Windows SmartScreen 可能弹出警告:选择更多信息 › 仍要运行。

登录

运行 tfile auth login,它会在浏览器中打开一个带代码的地址。照常登录(密码、两步验证、通行密钥或单点登录),确认页面显示的是同一个代码,选择 tfile 能做什么、限定哪个文件夹、多久到期,然后批准。tfile 随即收到它的 API 令牌。--no-browser 只显示地址,可在另一台设备上打开。代码只能用一次,十分钟内有效。

tfile auth login --server https://drive.example.com
tfile auth whoami

也可以在网页界面账号菜单的 API 令牌中创建令牌后粘贴:tfile auth login --with-token,或用管道传入。粘贴时不会显示,令牌也不会放在命令参数里。

脚本和服务器可以改用环境变量提供地址和令牌,这样不会保存任何内容:

export THIRTYFILE_URL=https://drive.example.com
export THIRTYFILE_TOKEN=tft_…

指定文件和文件夹

tfile files list "/My files/Reports"
tfile files list Reports
tfile files list . --space "Team"
tfile files get id:4f2c…
在 Windows 的 Git Bash 中,以 / 开头的参数会被 shell 改写。请使用相对路径或 ID,或设置 MSYS_NO_PATHCONV=1。

命令

命令形如 tfile files move。可以按想做的事查找命令,再查看它需要什么:

tfile cli search "move files into a folder"
tfile schema files move
tfile files move --help

常见任务:

tfile files list Reports
tfile files search invoice --ext pdf
tfile files download Reports/q3.pdf --output q3.pdf
tfile files upload q3.pdf summary.md Reports
tfile files upload ./photos Reports
tfile files folders create "Reports/2026"
tfile files move Reports/q3.pdf Archive
tfile files rename id:4f2c… "q3 final.pdf"
tfile files archive create Reports Archive
tfile files versions list Reports/q3.pdf
tfile files trash Reports/old.txt --force
tfile trash list
tfile trash restore id:4f2c…
tfile files text get Reports/q3.docx

按 Tab 键补全

tfile complete 会按你登录的服务器的命令,输出 bash、zsh、fish、PowerShell 或 elvish 的补全脚本。在 shell 的启动文件中加载它;服务器更新后重新生成。

# bash (~/.bashrc)
source <(tfile complete bash)
# zsh (~/.zshrc)
source <(tfile complete zsh)
# fish
tfile complete fish > ~/.config/fish/completions/tfile.fish
# PowerShell ($PROFILE)
tfile complete powershell | Out-String | Invoke-Expression

安全地更改

tfile files move Reports/q3.pdf Archive --dry-run
tfile files upload q3.pdf Reports --on-conflict keep
tfile files content update Reports/notes.txt notes.txt --if-version 1790000000

管理员的令牌若有查看管理(admin.read)就能读取它:tfile users list、tfile settings get、tfile logs sign-ins list、tfile usage get、tfile storage list、tfile backups list,以及 tfile cli search 找得到的其他命令。这种令牌最长有效 90 天,不能限定在文件夹内,账号不再是管理员时就会失效;密码、密钥等机密不会出现在回应中。列出备份或存储位置里的内容(tfile backups snapshots browse、tfile storage objects list)和下面这些操作一样要等你批准。有此权限的令牌要分享(tfile shares、access、buckets、ftp-folders)、永久删除或清空回收站时,会等待你在浏览器中批准:tfile 显示地址并等到你批准或拒绝,再显示结果。--no-wait 会立即显示批准请求,之后可用 tfile approvals wait <id> 跟进。--force 不会跳过批准。

有管理(admin.users、admin.spaces、admin.storage 和 admin.settings)的管理员令牌还能更改控制面板。可以撤销的更改会立即执行:tfile spaces create、tfile branding update、tfile storage test、tfile moves pause。其他更改和分享一样要等你批准,批准页面会写出它涉及的账号、空间或存储位置:tfile users create、tfile users update、tfile groups update、tfile settings update、tfile storage update、tfile backups policies create。只有本人能在网页界面做的操作,例如电子邮件设置、单点登录或添加存储位置,不是命令:tfile cli search 和 tfile schema 找得到它,并写明 browser only 和原因;直接输入会以 browser_only 失败。只有本人能发送的字段,例如账号的密码或角色,会以 browser_only_field 拒绝;tfile schema 在 browser_only_fields 列出这些字段。

tfile users create amy --display-name "Amy Chen"
tfile cli search "change the email server"

输出和退出码

结果以 JSON 写到标准输出,消息和错误写到标准错误。列表格式为 {"items": […], "next": …},每页 50 项。搜索也一页一页返回。

tfile files list Reports --limit 20
tfile files list Reports --limit 20 --cursor "…"
tfile files list Reports --all

错误格式为 {"error": {"code": …, "message": …}},退出码表示错误类型:

退出码含义
0成功
1其他失败,或你选择不执行
2命令或参数错误
3未登录,或令牌已失效
4找不到,或你的账号看不到
5权限不足
6名称已被使用,或期间有变动
7稍后再试
9只完成了一部分
10需要 --force

错误的 code 比退出码更详细,而且各版本之间不变。常见的有:

代码退出码含义
name_taken6那里已有同名项目
version_conflict6文件已不是 --if-version 指定的版本
not_empty6文件夹不是空的
busy7项目还在更改中
space_moving7空间正在迁移到其他存储位置
storage_unavailable7磁盘或存储服务没有响应
read_only5空间是只读的
token_permission5API 令牌缺少权限
token_folder5令牌限定在一个文件夹:超出范围,或是文件夹本身
token_folder_gone3令牌的文件夹已不存在,或账号已无法打开它
token_not_admin3管理用的令牌,其账号已不是管理员
browser_only5只有本人能在网页界面做这件事
browser_only_field5只有本人能在网页界面发送的字段(密码、角色、凭据)
approval_refused5在浏览器中被拒绝:没有任何更改
approval_expired7十分钟内无人批准
approval_failed1已批准但没有执行(它指定的项目在此期间有变动)
too_many_approvals7这个令牌已有五个批准请求在等待
too_many_items2超过一次请求能处理的项目数
content_search_off6文件内搜索已关闭

配置

一个配置保存一组服务器和令牌。可以为不同服务器或令牌建立多个,并绑定到文件夹:

tfile auth create work --server https://drive.example.com
tfile auth activate work ~/projects/reports
tfile auth list
tfile files list --profile work

单用户模式

单用户模式没有令牌:

tfile auth login --server http://localhost:8080 --no-token
没有令牌就没有任何限制:这台电脑上的任何程序都能做网页能做的事,包括永久删除。设置 THIRTYFILE_KEEP_HISTORY=false 时没有回收站:tfile files trash 会永久删除。