命令行工具
tfile 让你在终端处理文件,适合脚本、备份和 AI Agent。它用 API 令牌登录,能做的事以令牌和你的账号权限为限。
安装
每个版本都附带各系统的程序。下载与你系统相符的文件:
| 系统 | 文件 |
|---|---|
| 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/ThirtyFilexattr -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_…- 地址必须是
https,只有本机(localhost)可以用http。 - 令牌只会发送到一起提供的地址。不跟随重定向,也不读取任何
.env文件。 - 也可以使用应用密码(有自己的限制),但 API 令牌更安全。
指定文件和文件夹
- 从顶层开始的路径:
/My files/Reports/q3.pdf。别人分享给你的在Shared with me之下。 - 相对于某个空间的路径:用
--space或THIRTYFILE_SPACE选择,默认是我的文件(路径中写My files)。.代表空间本身。 - ID:
id:…。结果都带有 ID,重命名或移动后 ID 不变。回收站里的项目用 ID 指定。
tfile files list "/My files/Reports"
tfile files list Reports
tfile files list . --space "Team"
tfile files get id:4f2c…/ 开头的参数会被 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.docxfiles text get返回为文件内搜索从文档读出的文字(需管理员开启文件内搜索),代理不用下载、打开文件就能读取内容。- 使用限定在一个文件夹的令牌时,相对路径从该文件夹开始(
tfile files list .列出它的内容),找不到文件夹以外的任何东西。 files download下载文件夹时会保存为 ZIP 文件。files upload可以上传文件和文件夹。文件夹会连同里面的内容一起上传(链接和空文件夹除外)。连接中断时会自动续传;命令中途停止时,再运行一次同样的命令即可,已送达的部分不会重复上传。只要文件没有改动,一周内都能这样续传。tfile mcp让 AI 工具通过 MCP 处理你的文件:请见 AI Agent。- 命令来自服务器的 API 说明,登录时保存。服务器更新后,运行
tfile auth whoami获取新命令。
按 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
安全地更改
--dry-run只显示请求,不发送。- 会拿走内容的更改会先询问;在脚本中不加
--force就不执行。 - 名称已被使用时会拒绝。用
--on-conflict keep(两个都保留)或replace(替换)决定。 --if-version只在文件仍是你读到的版本(updated_at)时保存新内容。- 耗时任务会跟踪到完成。
--no-wait立即返回,之后用tfile jobs wait跟踪。
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_taken | 6 | 那里已有同名项目 |
version_conflict | 6 | 文件已不是 --if-version 指定的版本 |
not_empty | 6 | 文件夹不是空的 |
busy | 7 | 项目还在更改中 |
space_moving | 7 | 空间正在迁移到其他存储位置 |
storage_unavailable | 7 | 磁盘或存储服务没有响应 |
read_only | 5 | 空间是只读的 |
token_permission | 5 | API 令牌缺少权限 |
token_folder | 5 | 令牌限定在一个文件夹:超出范围,或是文件夹本身 |
token_folder_gone | 3 | 令牌的文件夹已不存在,或账号已无法打开它 |
token_not_admin | 3 | 管理用的令牌,其账号已不是管理员 |
browser_only | 5 | 只有本人能在网页界面做这件事 |
browser_only_field | 5 | 只有本人能在网页界面发送的字段(密码、角色、凭据) |
approval_refused | 5 | 在浏览器中被拒绝:没有任何更改 |
approval_expired | 7 | 十分钟内无人批准 |
approval_failed | 1 | 已批准但没有执行(它指定的项目在此期间有变动) |
too_many_approvals | 7 | 这个令牌已有五个批准请求在等待 |
too_many_items | 2 | 超过一次请求能处理的项目数 |
content_search_off | 6 | 文件内搜索已关闭 |
配置
一个配置保存一组服务器和令牌。可以为不同服务器或令牌建立多个,并绑定到文件夹:
tfile auth create work --server https://drive.example.com
tfile auth activate work ~/projects/reports
tfile auth list
tfile files list --profile work- 命令依次使用:
THIRTYFILE_TOKEN(搭配THIRTYFILE_URL)、--profile、THIRTYFILE_PROFILE、当前文件夹绑定的配置、默认配置。 - 配置保存在
~/.config/tfile(Linux)、~/Library/Application Support/tfile(macOS)或%APPDATA%\tfile(Windows),可用THIRTYFILE_CONFIG_DIR更改。令牌存在只有你能读取的文件中,未加密(用--use-keyring登录时除外)。 tfile auth login --use-keyring会把令牌改存到系统钥匙串:macOS 用钥匙串,Windows 用凭据管理器,Linux 通过secret-tool程序(软件包libsecret-tools)使用 Secret Service(GNOME Keyring、KWallet)。之后再登录也会存在那里;--no-use-keyring可改回文件。tfile auth whoami会显示存放位置。tfile auth logout会在服务器上停用 API 令牌,并从这台电脑上清除。应用密码只会在这里清除,请到网页界面移除。
单用户模式
单用户模式没有令牌:
tfile auth login --server http://localhost:8080 --no-tokenTHIRTYFILE_KEEP_HISTORY=false 时没有回收站:tfile files trash 会永久删除。