All Products
Search
Document Center

Object Storage Service:list-objects-v2 (get-bucket-v2)

Last Updated:Jan 09, 2025

Lists all objects in a bucket.

Usage notes

  • By default, an Alibaba Cloud account has the permissions to list all objects in a bucket. To list all objects in a bucket by using a RAM user or Security Token Service (STS), you must have the oss:ListObjects permission. For more information, see Attach a custom policy to a RAM user.

  • The user metadata is not returned for a GetBucketV2 (ListObjectsV2) request.

Command syntax

ossutil api list-objects-v2 --bucket value [flags]

Parameter

Type

Description

--bucket

string

The name of the bucket.

--continuation-token

string

The token from which the list operation starts.

--delimiter

string

The character that you want to use to group objects by name.

--encoding-type

string

The encoding type of the object names in the response.

--fetch-owner

string

Specifies whether to include the object owner information in the response.

--max-keys

int

The maximum number of objects that can be returned.

--prefix

string

The prefix that the returned object names must contain.

--start-after

string

The position from which the list operation starts. Objects whose names are alphabetically after the value of this parameter are returned in sequence.

Note
  • The list-objects-v2 (get-bucket-v2) command corresponds to the ListObjectsV2 (GetBucketV2) operation. For more information about the parameters in the ListObjectsV2(GetBucketV2) operation, see ListObjectsV2 (GetBucketV2).

  • For more information about supported global command-line options, see Global command-line options.

Examples

Run the following command to list all objects in a bucket named examplebucket:

ossutil api list-objects-v2 --bucket examplebucket

Run the following command to list all objects in a bucket named examplebucket and display the results in the JSON format:

ossutil api list-objects-v2 --bucket examplebucket --output-format json

Run the following command to list all objects in a bucket named examplebucket and display the results in the YAML format:

ossutil api list-objects-v2 --bucket examplebucket --output-format yaml

Run the following command to list all objects whose names contain the dir prefix in a bucket named examplebucket:

ossutil api list-objects-v2 --bucket examplebucket --prefix dir

Run the following command to list the first 100 objects whose names contain the dir prefix in a bucket named examplebucket:

ossutil api list-objects-v2 --bucket examplebucket --prefix dir --max-keys 100

Run the following command to list the objects in the current directory of a bucket named examplebucket:

ossutil api list-objects-v2 --bucket examplebucket --delimiter /

Run the following command to list the objects whose names are alphabetically after test.txt in a bucket named examplebucket:

ossutil api list-objects-v2 --bucket examplebucket --start-after test.txt

Run the following command to list all objects in a bucket named examplebucket and URL-encode the names of the objects:

ossutil api list-objects-v2 --bucket examplebucket --encoding-type url

Run the following command to list all objects in a bucket named examplebucket and include the owner information in the returned results:

ossutil api list-objects-v2 --bucket examplebucket --fetch-owner

Run the following command to list the objects after CgJiYw123 in a bucket named examplebucket:

ossutil api list-objects-v2 --bucket examplebucket --continuation-token CgJiYw123