tencent cloud

Listing Contents and Statistics Under a Directory - lsdu
Last updated: 2025-05-09 18:27:40
Listing Contents and Statistics Under a Directory - lsdu
Last updated: 2025-05-09 18:27:40
The lsdu command is used to obtain the contents of the current level with a specified prefix and to calculate the size and number of objects within it.
Note:
If you need to use this command, when you perform authorization policy, set action to cos:HeadBucket,cos:GetBucket. For more authorizations, please refer to CAM-Enabled API.

Command Syntax

./coscli lsdu cos://<bucket-name>[/prefix/] [flags]
The lsdu command includes the following parameters:
Parameter Format
Description
Example
cos://<bucket-name>
Specifies the target bucket, which is accessible by using the bucket alias or bucket name configured in the configuration file as detailed in Download and Installation Configuration. If you use the bucket name for access, you also need to include the endpoint flag.
Access with the bucket alias: cos://example-alias
Access with the bucket name: cos://examplebucket-1250000000
/prefix/
Specifies a directory (optional).
/picture/
The lsdu command includes the following optional flags:
Flag Abbreviation
Flag Name
Description
-h
--help
Views the usage of this command.
No
--include
Includes specific objects.
No
--exclude
Excludes specific objects.

Operation Example

Obtaining the statistics under the root directory of the bucket1 bucket

./coscli lsdu cos://bucket1/
The returned information includes the names of directories or objects, the total number of objects, and the total size. Below is an example:
NAME | OBJECTS COUNT | TOTAL SIZE
---------------------+---------------+-------------
300123/ | 1 | 300.00 MB
300s/ | 1 | 100.00 MB
300u/ | 301 | 8.22 GB
activity/ | 35 | 129.08 KB
test/ | 1 | 3 B
test100/ | 20 | 20.00 GB
test5/ | 6 | 9.00 GB
testrm/ | 1 | 0 B
10GB_file | 1 | 11.72 GB
1GB_file | 1 | 1.00 GB

Obtaining the statistics under the picture directory of the bucket1 bucket

./coscli lsdu cos://bucket1/picture/
Note:
When there are many files, this command may take a long time to run. It is recommended to run it in the background.
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback