All Products
Search
Document Center

Object Storage Service:mkdir

Last Updated:Apr 03, 2024

To organize objects in a bucket, you can use directories. This topic describes how to use the mkdir command to create directories in Object Storage Service (OSS).

Usage notes

  • To create a directory, you must have the oss:GetObject and oss:PutObject 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 mkdir oss://bucketname/dirname [--encoding-type <value>]

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

Parameter/Option

Description

bucketname

The name of the bucket.

dirname

The name of the directory that you want to create. A directory name must end with a forward slash (/). If you do not end the directory name with a forward slash (/), ossutil automatically adds one at the end.

--encoding-type

The encoding type used to encode the directory name, which is specified by the part following oss://bucket_name in the value of dirname. Valid value: url. If you do not specify this option, the directory name is not encoded.

Examples

You can perform the following steps to upload an object to the specified directory:

  1. Create a directory.

    • Create a single-level directory

      ./ossutil64 mkdir oss://examplebucket/dir/

      If the output is similar to the following content, the dir/ is created in the bucket named examplebucket.

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

      To further classify objects stored in a directory, you can create multi-level directories. For example, you can run the following command to create a subdirectory that is named 2021/ within the Photo/ directory to store images that are generated in 2021:

      ./ossutil64 mkdir oss://examplebucket/Photo/2021/ 

      If you delete the 2021/ subdirectory and its parent directory Photo/ does not contain any objects, the Photo/ directory is also deleted.

  2. Upload an object to the directory

    You can run the following command to upload an object named exampleobject.txt to the dir/ directory in a bucket named examplebucket:

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

    If the output is similar to the following content, the object is uploaded to the specified directory.

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

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 create a directory named dir/ in the examplebucket bucket that is located in the China (Hangzhou) region and owned by another Alibaba Cloud account:

./ossutil64 mkdir oss://examplebucket/dir/ -e oss-cn-hangzhou.aliyuncs.com -i LTAI4Fw2NbDUCV8zYUzA****  -k 67DLVBkH7EamOjy2W5RVAHUY9H****

For more information about other common options that you can use for the sync command, see Common options.