mkdir (create a directory)

更新时间:
复制 MD 格式

Use the mkdir command to create directories and organize objects in a bucket.

Usage notes

  • To create a directory, you must have the oss:GetObject and oss:PutObject permissions. Attach a custom access policy to a RAM user.

  • For ossutil 1.6.16 and later, use ossutil as the binary name in commands. You do not need to change the binary name based on your operating system. For versions earlier than 1.6.16, you must use the system-specific binary name. For more information, see ossutil command reference.

Command syntax

ossutil mkdir oss://bucketname/dirname [--encoding-type <value>]

The parameters and options are as follows:

Parameter

Description

bucketname

The destination bucket name.

dirname

The directory name. Must end with a forward slash (/). If you do not add a forward slash (/), ossutil automatically adds one.

--encoding-type

Encoding type for the key, which is the directory name after oss://bucket_name. Valid value: url. Default: not encoded.

Examples

Create a directory and upload an object to it.

  1. Create a directory.

    • Create a single-level directory

      ossutil mkdir oss://examplebucket/dir/

      The following output indicates that the dir/ directory is created in the examplebucket bucket.

      0.385877(s) elapsed
    • Create a multi-level directory

      Create multi-level directories to classify objects further. Example: create a Photo/2021/ directory in examplebucket:

      ossutil mkdir oss://examplebucket/Photo/2021/ 

      If you delete 2021/ and Photo/ contains no other objects, Photo/ is also removed.

  2. Upload an object to the destination directory

    Upload exampleobject.txt to the dir/ directory in examplebucket:

    ossutil cp exampleobject.txt oss://examplebucket/dir/

    The following output indicates that the file is uploaded to the destination directory.

    Succeed: Total num: 1, size: 0. OK num: 1(upload 1 files).
    
    average speed 0(byte/s)

Common options

To access a bucket in a different region, use -e to specify the endpoint. To access a bucket owned by a different Alibaba Cloud account, use -i for the AccessKey ID and -k for the AccessKey secret.

Example: create the dir/ directory in examplebucket, which is in the China (Hangzhou) region under a different Alibaba Cloud account:

ossutil mkdir oss://examplebucket/dir/ -e oss-cn-hangzhou.aliyuncs.com -i yourAccessKeyID  -k yourAccessKeySecret

Common options.