The ls command lists information about buckets, objects, and parts in your account. You can use this command to query and manage your OSS resources, such as finding and deleting large files.
Prerequisites
To list buckets, you must have the
oss:ListBucketspermission.To list objects, you must have the
oss:ListObjectspermission.To list all versions of an object, you must have the
oss:ListObjectVersionspermission.To list all parts, you must have the
oss:ListPartsandoss:ListMultipartUploadspermissions.
For more information, see Grant custom access policies to RAM users.
Command format
ossutil ls [oss://bucket[/prefix]] [flags]Option | Type | Description |
--all-versions | / | Lists all versions of an object. |
-d, --dirs | / | Lists files and subdirectories in the current directory instead of recursively listing all files in all subdirectories. |
--encoding-type | string | Specifies the encoding type of the object or file names. The value can be `url`. |
--end-with | string | Lists objects that are lexicographically before the specified value. |
--exclude | stringArray | Exclusion rules for paths or file names. |
--exclude-from | stringArray | Reads exclusion rules from a rule file. |
--files-from | stringArray | Reads a list of source file names from a file. Empty lines or comment lines are ignored. |
--files-from-raw | stringArray | Reads a list of source file names from a file. |
--filter | stringArray | Filtering rules for paths or file names. |
--filter-from | stringArray | Reads filtering rules from a rule file. |
-f, --force | / | Forces the operation without a confirmation prompt. |
--include | stringArray | Inclusion rules for paths or file names. |
--include-from | stringArray | Reads inclusion rules from a rule file. |
--limited-num | int | The maximum number of results to return. |
--list-objects | / | Uses the ListObjects API operation to list objects. |
--max-size | SizeSuffix | Specifies the maximum size of files to list. The default unit is byte. You can also use suffixes such as B, K, M, G, T, or P. 1 K (KiB) = 1024 B. |
--metadata-exclude | stringArray | Exclusion rules for object metadata. |
--metadata-filter | stringArray | Filtering rules for object metadata. |
--metadata-filter-from | stringArray | Reads object metadata filtering rules from a rule file. |
--metadata-include | stringArray | Inclusion rules for object metadata. |
--min-age | Duration | Lists only files modified before the specified time interval. The default unit is second. You can also use a unit suffix. For example, 1h indicates 1 hour. Note
|
--max-age | Duration | Lists only files modified within the specified time interval. The default unit is second. You can also use a unit suffix. For example, 1h indicates 1 hour. Note
|
--min-mtime | Time | Lists only files modified after the specified time. The time must be in UTC format. For example, 2006-01-02T15:04:05. Note
|
--max-mtime | Time | Lists only files modified before the specified time. The time must be in UTC format. For example, 2006-01-02T15:04:05Z. |
--min-size | SizeSuffix | Specifies the minimum size of files to list. The default unit is byte. You can also use suffixes such as B, K, M, G, T, or P. 1 K (KiB) = 1024 B. |
--multipart | / | Specifies that the operation applies to incomplete multipart upload events in the bucket. |
--page-size | int | The maximum number of objects to list per page for batch processing. Default value: 1000. Valid values: 1 to 1000. |
-r, --recursive | / | Performs the operation recursively. If you specify this option, the command is run on all matching objects in the bucket. Otherwise, the command is run only on the objects in the specified path. |
--request-payer | string | The payment method for the request. Set this to `requester` if you use the pay-by-requester mode. |
--short-format | / | Displays results in short format. If you do not specify this option, the results are displayed in long format by default. |
--start-after | string | Lists objects that are lexicographically after the specified value. |
--resource-group-id | string | Specifies the ID of the resource group. |
For more information, see Command-line options.
Usage examples
List all buckets.
ossutil lsList all objects in the `examplebucket` bucket.
ossutil ls oss://examplebucketList all objects with the prefix `dir` in the `examplebucket` bucket.
ossutil ls oss://examplebucket/dirList all objects directly within the `dir` folder in the `examplebucket` bucket.
ossutil ls oss://examplebucket/dir -dList the first 100 objects with the prefix `dir` in the `examplebucket` bucket.
ossutil ls oss://examplebucket/dir --limited-num 100List all `.txt` files in the `dir1` and `dir2` folders of the `examplebucket` bucket.
ossutil ls oss://examplebucket/ --include "/dir1/**.txt" --include "/dir2/**.txt"List all files created in the last three days in the `dir1` and `dir2` folders of the `examplebucket` bucket.
ossutil ls oss://examplebucket --include "/dir1/**" --include "/dir2/**" --max-age 3dList all buckets and display the output in JSON format.
ossutil ls --output-format json