All Products
Search
Document Center

Object Storage Service:du

Last Updated:Aug 13, 2024

The du command queries the total size of all objects within a bucket or directory.

Usage notes

  • To query the total size of all current versions of objects in a bucket or a directory, you must have the oss:ListObjects, oss:ListParts, and oss:ListMultipartUploads permissions. To query the total size of all versions of objects in a bucket or a directory, you must have the oss:ListObjectVersions, oss:ListParts, and oss:ListMultipartUploads permissions. For more information, see Attach a custom policy to a RAM user.

  • For ossutil 1.6.16 and later, you can directly use ossutil as the binary name in the command line. You do not need to update the binary name based on the operating system. For ossutil earlier than 1.6.16, you must specify a binary name that corresponds to the operating system. For more information, see ossutil command reference.

Command syntax

ossutil du oss://bucketname[/prefix] [--payer requester] [--all-versions][--block-size <value>]

The following table describes the parameters and options in the command syntax.

Parameter/Option

Description

bucketname

The name of the bucket.

prefix

The directory or prefix in the names of the objects.

--payer

The payer of the request. If you want the requester who accesses the resources in the specified path to pay for the traffic and request, set this option to requester.

--all-versions

Specifies that the command queries the total size of all versions of objects. If you do not specify this option, the total size of only the current versions of objects is queried.

--block-size

The unit of the total size of objects within the specified bucket or directory. Valid values: KB, MB, GB, and TB. If you do not specify this option, the size of objects is measured in bytes.

Important

This option is available for ossutil 1.7.3 and later.

Query the total size of all versions of objects in a bucket

You can run the following sample command to query the total size of all versions of objects in the examplebucket bucket:

ossutil du oss://examplebucket --all-versions

The following sample output shows that the bucket contains a total of 13 objects (12 Standard objects and 1 Archive object), whose total size is 132,116,024 bytes.

storage class   object count            sum size(byte)
----------------------------------------------------------
Standard        12                       132115210
Archive         1                        814
----------------------------------------------------------
total object count: 13                          total object sum size: 132116024
total part count:   0                           total part sum size:   0

total du size(byte):132116024

0.382978(s) elapsed

Query the total size of the current versions of objects in a directory

You can run the following sample command to query the total size of the current versions of objects in the dir directory in a bucket named examplebucket. The obtained size is measured in GB.

ossutil du oss://examplebucket/dir/  --block-size GB

The following sample output shows that the dir directory in the bucket contains a total of 5 Standard objects, whose total size is 0.0002 GB.

storage class   object count            sum size(byte)
----------------------------------------------------------
Standard        5                       232277
----------------------------------------------------------
total object count: 5                           total object sum size: 232277
total part count:   0                           total part sum size:   0

total du size(GB):0.0002

0.078757(s) elapsed

Query the total size of all versions of objects whose names contain a specific prefix

You can run the following command to query the total size of all versions of objects whose names contain the test prefix in a bucket named examplebucket. The obtained size is measured in KB.

ossutil du oss://examplebucket/test --all-versions --block-size KB

The following sample output shows that 4 Standard objects whose names contain the test prefix are stored in the examplebucket bucket and that the total size of these objects is 448.1455 KB.

storage class   object count            sum size(byte)
----------------------------------------------------------
Standard        4                       439425
----------------------------------------------------------
total object count: 4                           total object sum size: 439425
total part count:   0                           total part sum size:   0

total du size(KB):448.1455

0.126340(s) elapsed

Common options

If you use ossutil to switch to a bucket that is located in another region, add the -e option to the command to specify the endpoint of the region in which the specified bucket is located. If you use ossutil to switch to a bucket that belongs to another Alibaba Cloud account, add the -i option to the command to specify the AccessKey ID of the specified account, and add the -k option to the command to specify the AccessKey secret of the specified account.

For example, you can run the following command to query the total size of all versions of objects in a bucket named testbucket, which is located in the China (Shanghai) region and owned by another Alibaba Cloud account:

ossutil du oss://testbucket --all-versions -e oss-cn-shanghai.aliyuncs.com -i LTAI4Fw2NbDUCV8zYUzA****  -k 67DLVBkH7EamOjy2W5RVAHUY9H****

For more information about common options, see Common options.