命令列工具

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 會永久刪除。