All Products
Search
Document Center

Object Storage Service:stat

Last Updated:Aug 19, 2024

This topic describes how to run the stat command to query the information of buckets or objects. For example, you can use this command to query the storage class of a bucket and metadata of an object.

Important
  • 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 need to update the binary name based on the operating system. For more information, see ossutil command reference.

  • Only the bucket owner and RAM users that have the oss:GetObject, oss:GetObjectAcl, and oss:GetBucketInfo permissions are allowed to use the stat command to query object metadata.

Command syntax

ossutil stat oss://bucketname[/objectname]
[--encoding-type <value>]
[--payer <value>]
[--version-id <value>]

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

Parameter/Option

Description

bucketname

The name of the bucket.

objectname

The name of the object whose information you want to query.

--encoding-type

The encoding of the object name. Valid value: url. If this option is not specified, the object name is not encoded.

--payer

The payer of the fees that are generated by the operation. If you want the requester who accesses the resources in the specified path to pay the fees that are generated by the operation, such as traffic and request fees, set this parameter to requester.

--version-id

The version ID of the object. This parameter applies only to a versioning-enabled or versioning-suspended bucket.

Examples

  • Query the information of the examplebucket bucket.

     ossutil stat oss://examplebucket

    The following sample output indicates that the command obtained information about the examplebucket bucket, such as the bucket name, region, creation time, and access control list (ACL).

    Name              : examplebucket
    Location          : oss-cn-hangzhou
    CreationDate      : 2021-06-30 16:04:41 +0800 CST
    ExtranetEndpoint  : oss-cn-hangzhou.aliyuncs.com
    IntranetEndpoint  : oss-cn-hangzhou-internal.aliyuncs.com
    ACL               : private
    Owner             : 148562088256****
    StorageClass      : Standard
    RedundancyType    : LRS
    AccessMonitor     : Enabled
    
    0.132413(s) elapsed
  • Query the information of the exampleobject.jpg object in the examplebucket bucket.

    ossutil stat oss://examplebucket/exampleobject.jpg

    The following sample output indicates that the command obtained information about the exampleobject.jpg object, such as the ACL, Content-Type, ETag, and last modified time.

    ACL                   : default
    Accept-Ranges         : bytes
    Content-Length        : 8746
    Content-Md5           : cvc5wcklut76CVoEi2UW****
    Content-Type          : image/jpeg
    Etag                  : 72F739C1C925BADEFA095A048B65****
    Last-Modified         : 2021-07-27 09:53:03 +0800 CST
    Owner                 : 148562088256****
    X-Oss-Hash-Crc64ecma  : 56037670485008****
    X-Oss-Object-Type     : Normal
    X-Oss-Storage-Class   : Standard
    
    0.194739(s) elapsed
  • Query the information of objects with special characters included in object names in the examplebucket bucket.

    For example, you want to query the information of the 示例.txt object in the examplebucket bucket. ossutil supports only URL encoding for object names. If an object name contains special characters, you must encode these special characters into URL-safe characters before you use the object name in the command.

    ossutil stat oss://examplebucket/%E7%A4%BA%E4%BE%8B.txt --encoding-type url

    The following sample output indicates that the command obtained information about the 示例.txt object, such as the ACL, Content-Type, ETag, and last modified time.

    ACL                   : default
    Accept-Ranges         : bytes
    Content-Length        : 113089
    Content-Md5           : mAYgHM5cSkZNBxKDDqqW****
    Content-Type          : image/jpeg
    Etag                  : 9806201CCE5C4A464D0712830EAA****
    Last-Modified         : 2021-07-27 10:08:57 +0800 CST
    Owner                 : 148562088256****
    X-Oss-Hash-Crc64ecma  : 1106061527435521****
    X-Oss-Object-Type     : Normal
    X-Oss-Storage-Class   : Standard
    
    0.168335(s) elapsed
  • Query the information of the object of the specified version in the examplebucket bucket.

    ossutil stat oss://examplebucket/test.jpg --version-id  CAEQFRiBgICw.YSX1xciIDNiNzc3ZTdmNTQzOTQ1OTM4MWUwOWI1Y2M1ZTgz****

    For more information about how to query the versions of an object, see Is.

    The following sample output indicates that the command obtained information about the object, such as the ACL, Content-Type, ETag, last modified time, and version ID.

    ACL                   : default
    Accept-Ranges         : bytes
    Content-Length        : 190540
    Content-Md5           : aJQnxHQ2b+zW6hh0c+2y****
    Content-Type          : image/jpeg
    Etag                  : 689427C474366FECD6EA187473ED****
    Last-Modified         : 2021-07-27 10:19:25 +0800 CST
    Owner                 : 148562088256****
    X-Oss-Hash-Crc64ecma  : 1666171672179499****
    X-Oss-Object-Type     : Normal
    X-Oss-Storage-Class   : Standard
    X-Oss-Version-Id      : CAEQFRiBgICw.YSX1xciIDNiNzc3ZTdmNTQzOTQ1OTM4MWUwOWI1Y2M1ZTgz****
    
    0.213528(s) elapsed

Common options

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

For example, you can run the following command to query the information of the testbucket bucket that is located in the China (Shanghai) region and owned by another Alibaba Cloud account:

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

For more information about common options, see Common options.