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 object versions within a bucket or directory, you must have the
oss:ListObjects
,oss:ListParts
, andoss:ListMultipartUploads
permissions. To query the total size of all object versions within a bucket or directory, you must have theoss:ListObjectVersions
,oss:ListParts
, andoss:ListMultipartUploads
permissions. For more information, see Attach a custom policy to a RAM user.This topic provides sample command lines that are based on the 64-bit Linux system. For other systems, replace ./ossutil64 in the commands with the corresponding binary name. For more information, see ossutil command reference.
Command syntax
./ossutil64 du oss://bucketname[/prefix] [--payer requester] [--all-versions][--block-size <value>]
The following table describes the parameters and options in the 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 the traffic and request fees, set this option to requester. |
--all-versions | Specifies that the command queries the total size of all versions of the specified objects. If you do not specify this option in the command, the total size of only the current versions of the 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 total size of the objects is measured in bytes. Important This option is available in ossutil version 1.7.3 and later. |
Query the total size of all versions of objects in a bucket
The followings sample command queries the total size of all versions of objects in the examplebucket bucket:
./ossutil64 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
The following sample command queries the total size (GB) of all current object versions in the dir directory of the examplebucket bucket:
./ossutil64 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 the specified prefix
The following sample command queries the total size (KB) of all versions of objects whose names contain the "test" prefix in the examplebucket bucket:
./ossutil64 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 examplebucket 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, you can 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:
./ossutil64 du oss://testbucket --all-versions -e oss-cn-shanghai.aliyuncs.com -i LTAI4Fw2NbDUCV8zYUzA**** -k 67DLVBkH7EamOjy2W5RVAHUY9H****
For more information about common options, see Common options.