全部產品
Search
文件中心

Alibaba Cloud CLI:使用阿里雲CLI管理OSS資源

更新時間:Oct 12, 2025

阿里雲CLI整合了Object Storage Service (OSS)的命令列工具ossutil,您可以在統一的CLI環境中執行OSS資源管理操作。本文為您介紹基於阿里雲CLI使用ossutil的相關操作。

使用準備

  • ossutil是阿里雲官方提供的OSS命令列工具,支援通過Windows、Linux和macOS系統以命令列方式管理OSS資料。目前,ossutil以外掛程式形式深度整合至阿里雲CLI,您可以通過阿里雲CLI直接調用ossutil完成對儲存空間(Bucket)、檔案(Object)等核心資源的管理操作。

  • 自阿里雲CLIv3.0.304版本起,深度整合ossutil 2.0,向您提供更穩定、更高效的使用體驗。當前阿里雲CLI同時相容ossutil 1.0ossutil 2.0兩個版本,舊版本命令仍可正常使用。建議您將阿里雲CLI升級至最新版本,以獲得 ossutil 2.0 的全部新特性與效能提升。

  • 阿里雲CLI中ossutil 1.0ossutil 2.0主要差異如下:

    命令調用差異

    新版本命令由 oss 升級為 ossutil,便於區分功能模組並支援更多進階特性。

    版本

    命令格式

    ossutil 1.0(舊版本)

    aliyun oss

    ossutil 2.0(新版本)

    aliyun ossutil

    說明

    新版本命令由oss 變更為 ossutil,如需使用ossutil 2.0,請在指令碼或自動化任務中注意更新命令。

    命令差異

    差異項

    ossutil 1.0(舊版本)

    ossutil 2.0(新版本)

    bucket類配置

    按照功能進行分類,放在根命令下,例如logging、lifecycle。

    • 一個介面對應一個命令,放在ossutil api子命令下。

    • 配置參數同時支援XML和JSON格式。

    • 支援對輸出內容的格式轉換,例如轉換成JSON。

    rm命令

    • 支援刪除儲存空間。

    • 一次操作,支援刪除多種類型的資料,例如同時刪除對象和分區。

    樣本:rm oss://bucket/prefix -r -f -m 

    • 不支援刪除儲存空間,如果需要刪除儲存空間,請使用新增命令rb。

    • 一次操作,只能刪除一種類型的資料,例如刪除對象和分區時,需要分別調用。

    樣本:rm oss://bucket/prefix -r -f

    rm oss://bucket/prefix -m -r -f

    追加命令

    • 命令為appendfromfile。

    • 資料來源僅支援本地路徑。

    • 命令為append。

    • 資料來源支援本地路徑、OSS資源地址和標準輸入。

    cat命令

    僅支援輸出整個檔案內容。

    支援輸出部分檔案內容,例如前10個位元組或者最後10個位元組。

    cp命令

    對象間的拷貝只拷貝資料,不拷貝中繼資料和標籤。

    進行對象間的拷貝時,可通過--copy-props來控制中繼資料和標籤的複製規則:不拷貝、拷貝中繼資料、拷貝中繼資料和標籤。

    預設拷貝中繼資料和標籤。

    修改對象屬性(

    許可權、儲存類型、中繼資料和標籤)

    • 通過set-acl修改對象許可權。

    • 通過set-meta修改對象元資訊。

    • 通過cp命令,修改Object Storage Service類型和標籤。

    • 通過object-tagging命令修改對象標籤。

    • 對象屬性修改合并成一個命令set-props,根據需要修改的屬性參數選擇合適的介面,讓屬性修改更有效率。

    • 通過別名方式支援set-acl和set-meta,但是命令列參數和原命令參數不一致。

    • 支援豐富的中繼資料和標籤修改指令,包括 replace、update、purge和delete。

    預簽名

    • 命令名為sign。

    • 簽名的到期時間。僅支援時間間隔,例如120秒。

    • 命令名為presign。

    • 支援sign別名,但是命令列參數和原命令參數不一致。

    • 簽名的到期時間。既支援時間間隔,例如 120秒,也只支援絕對時間設定。

    • v4簽名下,限制產生操作7天的預簽名地址。

    版本恢複

    僅支援通過刪除“刪除標記”恢複最新版本。

    • 支援通過刪除“刪除標記”恢複最新版本。

    • 支援通過版本索引,採用複製方式恢複到指定版本。

    • 支援通過時間索引,採用複製方式恢複到指定版本。

    hash

    僅支援計算本地檔案雜湊值。

    • 支援本地檔案。

    • 支援物件路徑。

    • 支援大量操作。

    sync

    • 不使用--delete參數時,與cp命令效果相同,邊掃描源邊拷貝,沒有最大數量限制。

    • 使用--delete參數時,資料複製階段也採用邊掃描源邊拷貝模式。

    • 無論是否設定--delete參數,都有最大數量限制,預設值是100W,最大可以配置到500W。

    • 先掃描源端和目的端列表,然後同步資料,最後根據--delete選項刪除目的端檔案的工作模式,所以當結合--update/--size-only選項時,有更好的同步效能。

    選項差異

    差異項

    ossutil 1.0(舊版本)

    ossutil 2.0(新版本)

    --include

    --exclude

    • 僅支援對象/檔案名稱匹配。

    • 當包含多個include(包含)和exclude(排除)條件時,從左至右逐一運用每個規則,直至最後才能最終確定匹配的結果。

    • 支援對象/檔案名稱匹配。

    • 支援對象/檔案路徑匹配。

    • 當包含多個include(包含)和exclude(排除)條件時,從左至右按照順序運用規則,如果匹配到規則(包含或者排除),馬上停止後面的檢查。

    --snapshot-path

    支援

    不支援

    --encoding-type

    同時對輸入參數和輸出參數生效。

    • 進階命令中,該參數只對輸入參數生效,不對輸出結果生效。

    • API級命令中,該參數與介面的對應參數含義一致。

    目的端的排除選項

    僅支援--update。

    支援--update、-size-only、--checksum和--ignore-existing。

    速度限制

    僅支援上傳的限速,使用--max-speed設定選項。

    支援上傳和下載限速,使用--bandwidth-limit設定選項。

    預設配置

    簽名版本

    簽名版本1。

    簽名版本4。當使用v4預簽名時,最長有效期間為1周。

    HTTPS協議

    當不指定時,預設是HTTP協議。

    預設使用HTTPS協議。

    對象列舉介面

    使用ListObjects介面。

    預設使用ListObjectsV2介面,可以通過--list-objects切換到ListObjects介面。

    read-timeout

    用戶端讀寫逾時,預設值為1200秒。

    預設值20秒。

    connect-timeout

    用戶端連線逾時的時間,單位為秒,預設值為120秒。

    預設值10秒。

    斷點續傳

    支援,預設開啟。

    支援,預設關閉。

新版本

說明
  • 在新版本的阿里雲CLI中,ossutil 2.0支援自動檢查並升級至最新版本,您無需手動執行update命令。

  • ossutil 2.0版本與阿里雲CLI主程式版本相互獨立,更新不受CLI版本綁定限制。

命令結構

阿里雲CLI中ossutil 2.0命令格式如下:

aliyun ossutil command [argument] [flags]

aliyun ossutil command subcommond [argument] [flags]  

aliyun ossutil topic
  • argument:參數,為字串。

  • flags:選項,支援短名字風格-o[=value]/ -o [value]和長名字風格--options[=value]/--options[value]。如果多次指定某個排它參數,則僅最後一個值生效。

命令樣本如下:

  • 命令:aliyun ossutil cat oss://bucket/object

  • 多級命令:aliyun ossutil api get-bucket-cors --bucket bucketexample

  • 說明主題:aliyun ossutil filter

命令列表

ossutil 2.0提供了進階命令、API級命令、輔助命令等三類命令。

  • 進階命令:用於常用的對對象或者儲存空間的操作環境,例如儲存空間建立、刪除、資料拷貝、對象屬性修改等。

    命令名

    含義

    mb

    建立儲存空間

    rb

    刪除儲存空間

    du

    擷取儲存或者指定首碼所佔的儲存空間大小

    stat

    顯示儲存空間或者對象的描述資訊

    mkdir

    建立一個名字有尾碼字元/的對象

    append

    將內容上傳到追加類型的對象末尾

    cat

    將對象內容串連到標準輸出

    ls

    列舉儲存空間或者對象

    cp

    上傳、下載或拷貝對象

    rm

    刪除儲存空間裡的對象

    set-props

    設定對象的屬性

    presign

    產生對象的預簽名URL

    restore

    恢複冷凍狀態的對象為可讀狀態

    revert

    將對象恢複成指定的版本

    sync

    將本地檔案目錄或者對象從源端同步到目的端

    hash

    計算檔案/對象的雜湊值

  • API級命令:提供了API操作的直接存取,支援該介面的配置參數。

    命令名

    含義

    put-bucket-acl

    設定、修改Bucket的存取權限

    get-bucket-acl

    擷取存取權限

    ....

    put-bucket-cors

    設定跨域資源共用規則

    get-bucket-cors

    擷取跨域資源共用規則

    delete-bucket-cors

    刪除跨域資源共用規則

    ...

  • 輔助命令:例如設定檔的配置、額外的說明主題等。

    命令名

    含義

    help

    擷取協助資訊

    config

    建立設定檔用以儲存配置項和訪問憑證

    version

    顯示版本資訊

    probe

    探測命令

命令列選項

ossutil 2.0中的命令列選項分為全域命令列選項和局部命令列選項。全域命令列選項適用於所有命令,局部命令列選項僅適用於特定的命令。命令列選項的優先順序最高,可以覆蓋設定檔設定或環境變數設定的參數。

查詢命令列選項

執行以下命令查詢命令列選項:

ossutil cp -h

輸出內容如下:

Flags:
      --acl string                         The access control list (ACL) of the object, valid value(s): "private","public-read","public-read-write","default"
      --bandwidth-limit SizeSuffix         Bandwidth limit in B/s, or use suffix B|K|M|G|T|P
      --bigfile-threshold SizeSuffix       The threshold of file size, the file size larger than the threshold will use multipart upload, download or copy, or use suffix B|K|M|G|T|P (default 100Mi)
      --cache-control string               The caching behavior of the web page when the object is downloaded
      --checkers int                       Number of checkers to run in parallel (default 16)
      --checkpoint-dir string              The specified directory for breakpoint continuation information
      --checksum                           Only copy the source file with different size and checksum(if available)
      --content-disposition string         The method that is used to access the object
      --content-encoding string            The method that is used to encode the object
      --content-type string                The mime type of object
      --copy-props string                  Determines which properties are copied from the source object, valid value(s): "none","metadata","default"
  -d, --dirs                               Return matching subdirectory names instead of contents of the subdirectory
      --encoding-type string               The encoding type of object name or file name that user inputs, valid value(s): "url"
      --end-with string                    The name of the object from which the list operation ends, include
      --exclude stringArray                Exclude files matching pattern
      --exclude-from stringArray           Read exclude patterns from file
      --expires string                     The expiration time of the cache in UTC
      --files-from stringArray             Read list of source-file names from file, ignores blank and comment line
      --files-from-raw stringArray         Read list of source-file names from file without any processing of lines
      --filter stringArray                 A file-filtering rule
      --filter-from stringArray            Read file filtering rules from a file
  -f, --force                              Operate silently without asking user to confirm the operation
      --ignore-existing                    Skip all files that already exist on destination
      --include stringArray                Don't exclude files matching pattern
      --include-from stringArray           Read include patterns from file
  -j, --job int                            Amount of concurrency tasks between multi-files (default 3)
      --list-objects                       Use ListObjects instead of ListObjectsV2 to list objects
      --max-age Duration                   Don't transfer any file older than this, in s or suffix ms|s|m|h|d|w|M|y (default off)
      --max-mtime Time                     Don't transfer any file younger than this, UTC time format (default off)
      --max-size SizeSuffix                Don't transfer any file larger than size, in B or suffix B|K|M|G|T|P, 1K(KiB)=1024B
      --metadata strings                   Specifies the object's user metadata, in key=value foramt
      --metadata-directive string          The method that is used to configure the metadata of the destination object, valid value(s): "COPY","REPLACE"
      --metadata-exclude stringArray       Exclude metadata matching pattern
      --metadata-filter stringArray        A metadata-filtering rule
      --metadata-filter-from stringArray   Read metadata filtering rules from a file
      --metadata-include stringArray       Don't exclude metadata matching pattern
      --min-age Duration                   Don't transfer any file younger than this, in s or suffix ms|s|m|h|d|w|M|y (default off)
      --min-mtime Time                     Don't transfer any file older than this, UTC time format (default off)
      --min-size SizeSuffix                Don't transfer any file smaller than size, in B or suffix B|K|M|G|T|P, 1K(KiB)=1024B
      --no-error-report                    Don't generate error report file during batch operation
      --no-progress                        The progress is not displayed
      --output-dir string                  Specifies the directory to place output file in, output file contains: error report file generated during batch operation (default "ossutil_output")
      --page-size int                      The number of results to return in each response to a list operation (default 1000), in the range 1 - 1000
      --parallel int                       Amount of concurrency tasks when work with a file
      --part-size SizeSuffix               The part size, calculated the suitable size according to file size by default, or use suffix B|K|M|G|T|P, in the range 100Ki - 5Gi
  -r, --recursive                          Operate recursively, if the option is specified, the command will operate on all match objects under the bucket, else operate on the single object.
      --request-payer string               The payer of the request. set this value if you want pay for requester, valid value(s): "requester"
      --size-only                          Only copy the source file with different size
      --start-after string                 The name of the object from which the list operation starts, not include
      --storage-class string               The storage class of the object, valid value(s): "Standard","IA","Archive","ColdArchive","DeepColdArchive"
      --tagging strings                    Specifies the tag of the destination object, in key=value foramt
      --tagging-directive string           The method that is used to configure tags for the destination object, valid value(s): "COPY","REPLACE"
  -u, --update                             Only copy when the source file is newer than the destination file

Global Flags:
  -i, --access-key-id string        AccessKeyID while access oss
  -k, --access-key-secret string    AccessKeySecret while access oss
      --addressing-style string     The style in which to address endpoints (default "virtual"), valid value(s): "virtual","path","cname"
      --cloudbox-id string          The Id of the cloud box. It is applicable to cloud box scenarios
  -c, --config-file string          The path of the configuration file (default "~/.ossutilconfig")
      --connect-timeout int         The client connection timed out, the unit is: s (default 10)
  -n, --dry-run                     Do a trial run with no permanent changes
  -e, --endpoint string             The domain names that other services can use to access OSS.
  -h, --help                        help for the command
      --language string             The display text language
      --log-file string             Specifies the log output file. When -, outputs to Stdout
      --loglevel string             The debug message level (default "off"), valid value(s): "off","info","debug"
      --mode string                 Specifies the authentication mode, valid value(s): "AK","StsToken","EcsRamRole","Anonymous"
      --output-format string        The formatting style for command output (default "raw")
      --output-properties strings   The properties of output format
      --output-query string         A JMESPath query to use in filtering the response data
      --profile string              Specific profile from your config file.
      --proxy string                Specifies the proxy server. When 'env', use HTTP_PROXY and HTTPS_PROXY environment variables
  -q, --quiet                       Quiet mode, print as little stuff as possible
      --read-timeout int            The client read timed out, the unit is: s (default 20)
      --region string               The region in which the bucket is located.
      --retry-times int             Retry times when fail (default 10)
      --role-arn string             Specifies the ARN of role
      --role-session-name string    Specifies the session name
      --sign-version string         The version of the signature algorithm (default "v4"), valid value(s): "v1","v4"
      --skip-verify-cert            Specifies that the oss server's digital certificate file will not be verified
  -t, --sts-token string            STSToken while access oss

使用命令列選項

在命令列操作中,部分命令需要附加參數以指定操作對象或設定選項,而其他命令則不需要參數。對於帶參數的命令,您可以根據具體要求提供適當的參數值,以實現預期的功能,例如,帶參數的命令如:

ossutil ls --profile dev

ossutil ls --profile dev允許使用者通過參數值dev指定特定的設定檔。帶參數的選項通常需要通過空格或等號(=)將選項名稱與參數值分隔,例如--profile dev--profile=dev。當參數值包含空格時,必須使用雙引號將整個參數值括起來,以確保命令正確解析,例如 --description "OSS bucket list"

支援的全域命令列選項

參數

類型

說明

-i, --access-key-id

string

訪問OSS使用的AccessKey ID。

-k, --access-key-secret

string

訪問OSS使用的AccessKey Secret。

--addressing-style

string

請求地址的格式。取值範圍如下:

  • virtual(預設值),表示虛擬託管模式。

  • path,表示路徑模式。

  • cname,表示自訂網域名模式。

-c, --config-file

string

設定檔的路徑。 預設值為~\\.ossutilconfig

--connect-timeout

int

用戶端連線逾時的時間。單位為秒,預設值為10。

-n, --dry-run

/

在不進行任何更改的情況下執行試運行。

-e, --endpoint

string

對外服務的訪問網域名稱。

-h, --help

/

顯示協助資訊。

--language

string

顯示的語言。

--loglevel

string

記錄層級。取值範圍如下:

  • off(預設值)

  • info

  • debug

--mode

string

鑒權模式。取值:

  • AK,表示存取金鑰。

  • StsToken,表示臨時安全憑證。

  • EcsRamRole,表示使用ECS執行個體角色(RAM Role)進行鑒權。

  • Anonymous,表示匿名訪問。

--output-format

string

輸出格式,預設值為raw。

--output-query

string

JMESPath查詢條件。

--profile

string

指定設定檔裡的profile。

-q, --quiet

/

安靜模式,列印儘可能少的資訊。

--read-timeout

int

用戶端讀寫請求逾時時間。單位為秒,預設值為20。

--region

string

資料中心所在的地區,配置值可設定為cn-hangzhou。

--retry-times

int

當錯誤發生時的重試次數。預設值為10。

--sign-version

string

請求使用的簽名演算法版本。取值:

  • v1

  • v4(預設值)

--skip-verify-cert

/

表示不校正服務端的數位憑證。

-t, --sts-token

string

訪問OSS使用的STS Token。

--proxy

string

指定Proxy 伺服器,

配置值可以為以下幾種:

  • 直接配置:可以直接指定Proxy 伺服器的詳細資料,例如:

    • http://proxy.example.com:8080

    • https://proxy.example.com:8443

  • env:表示使用環境變數 HTTP_PROXY 和 HTTPS_PROXY 來擷取Proxy 伺服器資訊。使用者需要在作業系統中配置這兩個環境變數,例如:

    • HTTP_PROXY=http://proxy.example.com:8080

    • HTTPS_PROXY=https://proxy.example.com:8443

    配置這些環境變數後,將Proxy 伺服器選項的值設定為 env,系統將自動使用這些環境變數中的代理設定。

--log-file

string

指定日誌輸出檔案,配置值為:

  • -:表示將日誌輸出到標準輸出(Stdout)。

  • 檔案路徑:指定一個具體的檔案路徑,將日誌輸出到該檔案。

如果未指定日誌輸出檔案,輸出到預設設定檔上。

--cloudbox-id 

string

雲盒ID,應用於雲盒情境

命令選項類型

選項類型

選項

說明

字串

--option string

  • 字串參數可以包含ASCII字元集中的字母及數字字元、符號和空格。

  • 如果字串中包含空格,需要使用引號包括。

例如:--acl private。

布爾值

--option

開啟或關閉某一選項。

例如:--dry-run。

整數

--option Int

不帶正負號的整數。

例如:--read-timeout 10。

時間戳記

--option Time

ISO 8601格式,即DateTime或Date。

例如:--max-mtime 2006-01-02T15:04:05。

位元組單位尾碼

--option SizeSuffix

預設單位是位元組(B),也可以使用單位尾碼形式,支援的單位尾碼為:K(KiB)=1024位元組、M(MiB)、G(GiB)、G(GiB)、T(TiB)、P(PiB)、E(EiB)

例如:最小size為1024位元組

--min-size 1024

--min-size 1K

時間單位尾碼

--option Duration

時間單位,預設單位是秒。支援的單位尾碼為:ms 毫秒,s 秒,m 分鐘,h 小時,d 天,w 星期,M 月,y 年。

支援小數。例如:1.5天

--min-age 1.5d

字串列表

--option strings

支援單個或者多個同名選項,支援以逗號(,)分隔的多個值。

支援多選項輸入的單值。

例如:--metadata user=jack,email=ja**@test.com --metadata address=china

字串數組

--option stringArray

支援單個或者多個同名選項,只支援多選項輸入的單值。

例如 :--include *.jpg --include *.txt。

從非命令列中載入資料

一般情況下,參數的值都放在命令列裡,當參數值比較複雜時,需要從檔案載入參數值;當需要串聯多個命令操作時,需要標準輸中載入參數值。所以,對需要支援多種載入參數值的參數,做了如下約定:

  • file://開始的,表示從檔案路徑中載入。

  • 當參數值為-時,表示從標準輸入中載入。

例如, 設定儲存空間的跨網域設定,以JSON參數格式為例,通過檔案方式載入跨域參數。cors-configuration.json檔案如下:

{
  "CORSRule": {
    "AllowedOrigin": ["www.aliyun.com"],
    "AllowedMethod": ["PUT","GET"],
    "MaxAgeSeconds": 10000
  }
}
aliyun ossutil api put-bucket-cors --bucket examplebucket --cors-configuration file://cors-configuration.json

通過選項參數值載入跨域參數,cors-configuration.json的緊湊形式如下:

{"CORSRule":{"AllowedOrigin":["www.aliyun.com"],"AllowedMethod":["PUT","GET"],"MaxAgeSeconds":10000}}
aliyun ossutil api put-bucket-cors --bucket examplebucket --cors-configuration  "{\"CORSRule\":{\"AllowedOrigin\":[\"www.aliyun.com\"],\"AllowedMethod\":[\"PUT\",\"GET\"],\"MaxAgeSeconds\":10000}}"

從標準輸入載入參數的樣本如下:

cat cors-configuration.json | aliyun ossutil api put-bucket-cors --bucket examplebucket --cors-configuration -

控制命令輸出

輸出格式

對ossutil api下的子命令,以及du、stat、ls命令,支援通過--output-format參數調整其輸出格式,當前支援的格式如下:

格式名稱

說明

raw

以原始方式輸出,即服務端返回什麼內容,則輸出什麼內容。

json

輸出採用JSON字串的格式。

yaml

輸出採用YAML字串的格式。

例如:以get-bucket-cors為例,原始內容如下:

aliyun ossutil api get-bucket-cors --bucket bucketexample
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration>
  <CORSRule>
    <AllowedOrigin>www.aliyun.com</AllowedOrigin>
    <AllowedMethod>PUT</AllowedMethod>
    <AllowedMethod>GET</AllowedMethod>
    <MaxAgeSeconds>10000</MaxAgeSeconds>
  </CORSRule>
  <ResponseVary>false</ResponseVary>
</CORSConfiguration>

轉成JSON如下:

aliyun ossutil api get-bucket-cors --bucket bucketexample --output-format json
{
  "CORSRule": {
    "AllowedMethod": [
      "PUT",
      "GET"
    ],
    "AllowedOrigin": "www.aliyun.com",
    "MaxAgeSeconds": "10000"
  },
  "ResponseVary": "false"
}

篩選輸出

ossutil提供了基於JSON的內建用戶端篩選功能,通過--output-query value選項使用。

說明

該選項僅支援ossutil api下的子命令。

該功能基於JMESPath文法,當使用該功能時,會把返回的內容轉成JSON,然後再使用JMESPath進行篩查,最後按照指定的輸出格式輸出。有關JMESPath 文法的說明,請參見JMESPath Specification

例如:以get-bucket-cors為例,只輸出AllowedMethod內容,樣本如下:

aliyun ossutil api get-bucket-cors --bucket bucketexample --output-query CORSRule.AllowedMethod --output-format json
[
  "PUT",
  "GET"
]

友好顯示

對於進階命令(du、stat),提供了--human-readable選項,對位元組、數量資料,提供了以人類可讀方式輸出資訊。即位元組資料轉成Ki|Mi|Gi|Ti|Pi尾碼格式(1024 base),數量資料轉成k|m|g|t|p尾碼格式(1000 base)。

例如:原始模式

aliyun ossutil stat oss://bucketexample
ACL                         : private
AccessMonitor               : Disabled
ArchiveObjectCount          : 2
ArchiveRealStorage          : 10
ArchiveStorage              : 131072
...
StandardObjectCount         : 119212
StandardStorage             : 66756852803
Storage                     : 66756852813
StorageClass                : Standard
TransferAcceleration        : Disabled

友好模式

aliyun ossutil stat oss://bucketexample --human-readable
ACL                         : private
AccessMonitor               : Disabled
ArchiveObjectCount          : 2
ArchiveRealStorage          : 10
ArchiveStorage              : 131.072k
...
StandardObjectCount         : 119.212k
StandardStorage             : 66.757G
Storage                     : 66.757G
StorageClass                : Standard
TransferAcceleration        : Disabled

命令返回碼

通過進程等方式調用ossutil時,無法即時查看回顯資訊。ossutil支援在進程運行結束後,根據不同的運行結果產生不同的返回碼,具體的返回碼及其含如下。您可以通過以下方式擷取最近一次運行結果的返回碼,然後根據返回碼分析並處理問題。

Linux

執行命令擷取返回碼:echo $?

Windows

執行命令擷取返回碼:echo %errorlevel%

macOS

執行命令擷取返回碼:echo $?

返回碼

含義

0

命令操作成功,發送到服務端的請求執行正常,服務端返回200響應。

1

參數錯誤,例如缺少必需的子命令或參數,或使用了未知的命令或參數。

2

該命令已成功解析,並已對指定服務發出了請求,但該服務返回了錯誤(非2xx響應)。

3

調用OSS GO SDK時,遇到的非服務端錯誤。

4

大量操作時,例如cp、rm部分請求發生了錯誤。

5

中斷錯誤。命令執行過程中,您通過ctrl+c取消了某個命令。

操作樣本

  • 樣本1:上傳本地檔案upload.rar到bucket儲存空間中,上傳速度為20 MB/s,預設單位為位元組每秒(B/s)。

    aliyun ossutil cp D:\\upload.rar oss://bucket/ --bandwidth-limit 20971520
  • 樣本2:上傳本地檔案file.rar到bucket儲存空間中,上傳速度為50 MB/s,指定單位為MB每秒(MB/s)。

    aliyun ossutil cp D:\\file.rar oss://bucket/dir -r --bandwidth-limit 50M
  • 樣本3:將bucket儲存空間中的download.rar檔案下載到目前的目錄,並將下載速度限制為20 MB/s。

    aliyun ossutil cp oss://bucket/download.rar . --bandwidth-limit 20971520

舊版本

命令結構

aliyun oss [command] [args...] [options...]

命令列表

名稱

描述

access-monitor

配置儲存空間(Bucket)的訪問跟蹤狀態。

appendfromfile

用於在已上傳的追加類型檔案(Appendable Object)末尾直接追加內容。

bucket-cname

查看Bucket的CNAME配置。

bucket-encryption

添加、修改、查詢、刪除Bucket的加密配置。

bucket-policy

添加、修改、查詢、刪除Bucket的Bucket policy配置。

bucket-tagging

添加、修改、查詢、刪除Bucket的標籤配置。

bucket-versioning

添加或查詢Bucket的版本控制配置。

cat

將檔案內容輸出到ossutil。

config

建立設定檔來儲存OSS訪問資訊。

cors

添加、修改、查詢、刪除Bucket的CORS配置。

cors-options

用於測試Bucket是否允許指定的跨域訪問請求。

cp

用於上傳、下載、拷貝檔案。

create-symlink

建立符號連結(軟連結)。

du

用於擷取指定Bucket、指定Object或檔案目錄所佔的儲存空間大小。

getallpartsize

擷取Bucket內所有未完成上傳的Multipart任務的每個分區大小以及分區總大小。

hash

用於計算本地檔案的CRC64或MD5。

help

擷取命令的協助資訊。當您不清楚某個命令的用法時,建議您使用help命令擷取該命令的協助資訊。

inventory

命令用於添加、查詢、列舉、刪除Bucket的清單規則。

lifecycle

命令用於添加、修改、查詢、刪除生命週期規則配置。

listpart

列出沒有完成分區上傳的Object的分區資訊。

logging

添加、修改、查詢、刪除Bucket的日誌管理配置。

lrb

列舉單個或多個地區(Region)下Bucket的基本資料。

ls

列舉Bucket、Object和Part。

mb

建立Bucket。

mkdir

在Bucket內建立檔案目錄。

object-tagging

添加、修改、查詢或刪除Object的標籤配置。

probe

針對OSS訪問的檢測命令,可用於排查上傳、下載過程中因網路故障或基本參數設定錯誤導致的問題。

read-symlink

讀取符號連結(軟連結)檔案的描述資訊。

referer

添加、修改、查詢、刪除Bucket的防盜鏈配置。

replication

管理Bucket的跨地區複製規則配置。

request-payment

設定或查詢Bucket的要求者付費模式配置。

resource-group

為儲存空間(Bucket)配置所屬資源群組以及擷取資源群組資訊。

restore

恢複冷凍狀態的Object為可讀狀態。

revert-versioning

將已刪除的Object恢複至最近的版本。

rm

刪除Bucket、Object和Part。

set-acl

設定Bucket或Object的存取權限(ACL)。

set-meta

設定已上傳Object的中繼資料。

sign

用於產生經過簽名的檔案URL,並將簽名URL分享給第三方供其下載或預覽。

stat

擷取指定Bucket或Object的描述資訊。

style

設定圖片樣式。

sync

用於同步本地檔案到OSS、同步OSS檔案到本地、在OSS之間同步檔案。

update

用於更新ossutil版本。

website

用於添加、修改、查詢、刪除Bucket的靜態網站託管配置、重新導向配置、鏡像回源配置。

worm

管理Bucket的合規保留原則。

命令樣本

  • 樣本1:建立一個命名為vmeixme的儲存空間(Bucket),並設定Bucket的儲存類型為Standard

    aliyun oss mb oss://vmeixme --storage-class Standard
  • 樣本2:在Bucket內建立一個命名為horse的檔案目錄。

    aliyun oss mkdir oss://vmeixme/horse/
  • 樣本3:列舉您帳號下的OSS資源,包括儲存空間(Bucket)、對象(Object)和片段(Part)資訊,並設定返回結果的最大個數為20。

    aliyun oss ls --limited-num 20

常見問題

如您在使用ossutil時發現異常,可參考以下文檔進行錯誤排查。