list-objects命令用於列舉儲存空間(Bucket)中所有檔案(Object)的資訊。
注意事項
阿里雲帳號預設擁有列舉Bucket中的所有檔案的資訊。如果您需要通過RAM使用者或者STS的方式進行查看,您必須擁有
oss:ListObjects許可權。具體操作,請參見為RAM使用者授權自訂的權限原則。list-objects(get-bucket)已修訂為list-objects-v2(get-bucket-v2)。建議您在開發應用程式時使用較新的版本list-objects-v2(get-bucket-v2)。為保證向後相容性,OSS繼續支援list-objects(get-bucket)。
執行list-objects(get-bucket)請求時不會返回Object中自訂的元資訊。
命令格式
ossutil api list-objects --bucket value [flags]參數 | 類型 | 說明 |
--bucket | string | Bucket的名稱。 |
--delimiter | string | 對Object名字進行分組的字元。 |
--encoding-type | string | 對返回的內容進行編碼並指定編碼的類型。 |
--marker | string | 設定從marker之後按字母排序開始返回Object。 |
--max-keys | int | 指定返回Object的最大數。 |
--prefix | string | 限定返迴文件的Key必須以Prefix作為首碼。 |
list-objects命令對應API介面GetBucket(ListObjects)。關於API中的具體參數含義,請參見GetBucket (ListObjects)。
關於支援的全域命令列選項,請參見支援的全域命令列選項。
使用樣本
以下樣本展示了如何列舉儲存空間examplebucket 中所有Object的資訊。
ossutil api list-objects --bucket examplebucket以下樣本展示了如何列舉儲存空間examplebucket 中所有Object的資訊,以JSON格式顯示。
ossutil api list-objects --bucket examplebucket --output-format json以下樣本展示了如何列舉儲存空間examplebucket 中所有Object的資訊,以YAML格式顯示。
ossutil api list-objects --bucket examplebucket --output-format yaml以下樣本展示了如何列舉儲存空間examplebucket 中指定首碼dir下的所有Object的資訊。
ossutil api list-objects --bucket examplebucket --prefix dir以下樣本展示了如何列舉儲存空間examplebucket 中指定首碼dir下,前100個Object的資訊。
ossutil api list-objects --bucket examplebucket --prefix dir --max-keys 100以下樣本展示了如何列舉儲存空間examplebucket 中目前的目錄下的Object的資訊。
ossutil api list-objects --bucket examplebucket --delimiter /以下樣本展示了如何列舉儲存空間examplebucket 中指從test.txt之後的Object的資訊。
ossutil api list-objects --bucket examplebucket --marker test.txt以下樣本展示了如何列舉儲存空間examplebucket 中所有Object的資訊,並對Object的名字進行URL編碼。
ossutil api list-objects --bucket examplebucket --encoding-type url