All Products
Search
Document Center

Object Storage Service:create-symlink

Last Updated:Apr 03, 2024

Symbolic links are similar to shortcuts in Windows and enable quick access to objects in Object Storage Service (OSS). You can run the create-symlink command to create a symbolic link that points to an object in OSS.

Usage notes

  • To create a symbolic link, you must have the oss:PutObject permission. For more information, see Attach a custom policy to a RAM user.

  • This topic provides sample command lines that work 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 create-symlink cloud_url target_object
    [--encoding-type <value>] 
    [--payer <value>]

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

    Parameter/Option

    Description

    cloud_url

    The full path of the symbolic link you want to create.

    target_object

    The full path of the object to which the symbolic link points. A symbolic link and the object to which the symbolic link points must be in the same bucket.

    --encoding-type

    The method used to encode the object names specified in cloud_url and target_object. Valid value: url. If you do not specify this option, the names are not encoded.

    --payer

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

    Examples

    When you run the create-symlink command to create a symbolic link, ossutil does not check whether the object to which the symbolic link points to exists. If the object exists, the created symbolic link points to the object. If the object does not exist, the created symbolic link points to nothing. To determine whether the object to which a symbolic link points exists, run the ls command to query all objects in the bucket.

    The following examples show how to create a symbolic link that points to an existing object.

    Important

    If the name of the symbolic link you want to create is the same as that of an existing symbolic link in the bucket, the existing symbolic link is overwritten.

    • Create a symbolic link named test.jpg in the root directory of the examplebucket bucket and point the symbolic link to the exampleobject.jpg object in the root directory of the bucket.

      ./ossutil64 create-symlink  oss://examplebucket/test.jpg  oss://examplebucket/exampleobject.jpg
    • Create a symbolic link named example.jpg in the destfolder directory of the examplebucket bucket and point the symbolic link to the test.jpg object in the root directory of the bucket. Specify that all fees incurred when the command is run are paid by the requester.

      ./ossutil64 create-symlink  oss://examplebucket/destfolder/example.jpg  oss://examplebucket/test.jpg --payer requester
    • The following sample output indicates that the symbolic link is created for the object:

      0.106744(s) elapsed

      After the symbolic link is created, you can run the read-symlink or stat command to query the information about the symbolic link, such as the ETag value and the last update time.

    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 symbolic link named testobject.png for the exampleobject.png object in the testbucket bucket that is located in the China (Shanghai) region and owned by another Alibaba Cloud account:

    ./ossutil64 create-symlink  oss://testbucket/testobject.png  oss://testbucket/exampleobject.png -e oss-cn-shanghai.aliyuncs.com -i LTAI4Fw2NbDUCV8zYUzA****  -k 67DLVBkH7EamOjy2W5RVAHUY9H****

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