All Products
Search
Document Center

Object Storage Service:Get started with ossutil

Last Updated:Oct 18, 2024

ossutil is a command-line tool provided by Alibaba Cloud to efficiently manage objects in Object Storage Service (OSS). To upload objects to OSS, you must first create a bucket. After you upload objects, you can download the objects to your local device or share the objects with third-party users for downloads or previews by using signed URLs.

Prerequisites

Procedure

Compared with ossutil 1.0, ossutil 2.0 organizes commands in tiers and optimizes multiple items, such as configuration files, access credentials, and filters. If you are a new user of ossutil, we recommend that you use ossutil 2.0.

Get started with ossutil 2.0 (preview)

Step 1: Install ossutil 2.0

Linux

  1. Download the ossutil installation package.

    curl -o ossutil-2.0.2-beta.08282000-linux-amd64.zip https://gosspublic.alicdn.com/ossutil/v2-beta/2.0.2-beta.08282000/ossutil-2.0.2-beta.08282000-linux-amd64.zip
    Note

    In this example, ossutil is downloaded for a 64-bit Linux x86 system. For more information about how to download the ossutil installation package for other operating systems, see Install ossutil.

  2. Go to the directory in which the ossutil installation package is stored and run the following unzip command:

    unzip ossutil-2.0.2-beta.08282000-linux-amd64.zip
  3. Go to the directory in which ossutil is located and run the following command:

    chmod 755 ossutil
  4. Run the following command. If the version number of ossutil is returned, ossutil 2.0 is installed:

    ossutil version

Windows

  1. Click Windows x86 64bit or Windows x86 32bit to download the ossutil installation package based on the configurations of your computer.

  2. Decompress the ossutil installation package.

  3. Go to the directory in which the ossutil installation package is stored.

macOS

  1. Download the ossutil installation package.

    curl -o ossutil-2.0.2-beta.08282000-mac-arm64.zip  https://gosspublic.alicdn.com/ossutil/v2-beta/2.0.2-beta.08282000/ossutil-2.0.2-beta.08282000-mac-arm64.zip
    Note

    In this example, ossutil is downloaded for a 64-bit macOS ARM system. For more information about how to download the ossutil installation package for other operating systems, see Install ossutil.

  2. Run the following command to decompress the package:

    unzip ossutil-2.0.2-beta.08282000-mac-arm64.zip
  3. Go to the ~/ossutil-2.0.2-beta.08282000-mac-arm64 directory and run the following command:

    chmod 755 ossutil
  4. Run the following command. If the version number of ossutil is returned, ossutil 2.0 is installed.

    ossutil version

Step 2: Configure ossutil

  1. Run the following command to configure ossutil:

    ossutil config
  2. Specify the path of the configuration file.

    Please enter the config file name,the file name can include path(default /root/.ossutilconfig, carriage return will use the default file. If you specified this option to other file, you should specify --config-file option to the file when you use other commands):

    We recommend that you press the Enter key to use the default path. Default path: /root/.ossutilconfig.

  3. Specify the AccessKey ID, AccessKey secret, and region based on the on-screen instructions.

    Enter the AccessKey ID that you created.

    Please enter Access Key ID [None]:

    Enter the AccessKey secret that you created.

    Please enter Access Key Secret [None]:

    Enter the region in which the bucket that stores your data is located. Default value: cn-hangzhou.

    Please enter Region [cn-hangzhou]:
  4. Check whether ossutil is installed:

    ossutil

    If all commands supported by ossutil are displayed, ossutil is installed.

Step 3: Create a bucket

Run the following command to create a bucket named examplebucket:

ossutil mb oss://examplebucket

If the output is similar to the following content, the bucket is created.

0.668238(s) elapsed

Step 4: Upload an object

  1. Download the sample object named exampleobject.jpg to your local computer.

  2. Upload the downloaded sample object to the examplebucket bucket.

    ossutil cp exampleobject.jpg oss://examplebucket

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

    Success: Total 1 file, size 2078 B, Upload done:(1 objects, 2078 B), avg 5.985 KiB/s
    0.344043(s) elapsed

Step 5: Download an object

Run the following command to download the uploaded sample object named exampleobject.jpg from the examplebucket bucket to the localfolder directory in your computer:

ossutil cp oss://examplebucket/exampleobject.jpg localfolder/

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

Success: Total 1 object, size 13 B, Download done:(1 files, 13 B), avg 86 B/s
0.154553(s) elapsed

Step 6: Share an object

Run the following command to generate a pre-signed URL that has a default validity period of 15 minutes for an object named oss://examplebucket/exampleobject.jpg:

ossutil presign oss://examplebucket/exampleobject.jpg

If the output is similar to the following content, the pre-signed URL of the object is generated.

https://examplebucket.oss-cn-hangzhou.aliyuncs.com/exampleobject.jpg?x-oss-credential=LTAI5tAC9X28MocRaycC****%2F20240912%2Fcn-hangzhou%2Foss%2Faliyun_v4_request&x-oss-date=20240912T092928Z&x-oss-expires=900&x-oss-signature=fe72a66bf42cc619023e9ae289882a4d2443870b616ae1fba17eb81bb02a****&x-oss-signature-version=OSS4-HMAC-SHA256
0.002727(s) elapsed

Copy the pre-signed URL to the address bar of a browser to access the object.

Step 7: Release resources

Alibaba Cloud OSS uses the pay-as-you-go billing method. Fees continue to be generated during the object retention period. To prevent additional fees from being generated for the uploaded objects, release the resources after the preceding operations are complete.

  • Delete an object

    Run the following command to delete the sample object named exampleobject.jpg from the examplebucket bucket:

    ossutil rm oss://examplebucket/exampleobject.jpg

    If the output is similar to the following content, the object is deleted.

    0.295530(s) elapsed
  • Delete a bucket

    Run the following command to delete an empty bucket named examplebucket:

    ossutil rb oss://examplebucket

    If the output is similar to the following content, the bucket is deleted.

    0.478659(s) elapsed

The preceding steps describe the basic usage of ossutil 2.0. For more information, see ossutil 2.0 (preview).

Get started with ossutil 1.0

Step 1: Install ossutil 1.0

Linux

  1. Install the unzip tool.

    sudo yum install -y unzip
  2. Run the following command to install ossutil:

    sudo -v ; curl https://gosspublic.alicdn.com/ossutil/install.sh | sudo bash
    Note

    By default, ossutil is installed in the /usr/bin directory.

Windows

  1. Click Windows x86 64bit or Windows x86 32bit to download the ossutil installation package based on the configurations of your computer.

  2. Decompress the installation package and run the ossutil.bat file.

macOS

Run the following command to install ossutil:

sudo -v ; curl https://gosspublic.alicdn.com/ossutil/install.sh | sudo bash
Note

By default, ossutil is installed in the /usr/local/bin directory.

Step 2: Configure ossutil

  1. Run the following command to configure ossutil:

    ossutil config
  2. Specify the path of the configuration file.

    Please enter the config file name,the file name can include path(default /root/.ossutilconfig, carriage return will use the default file. If you specified this option to other file, you should specify --config-file option to the file when you use other commands):

    We recommend that you press the Enter key to use the default path. Default path: /root/.ossutilconfig.

  3. Follow the on-screen instructions to specify the language of ossutil. Enter CH or EN. By default, ossutil is displayed in the language that is used by the OS. This configuration item takes effect after you run the config command. We recommend that you enter CH.

  4. Specify the AccessKey ID, AccessKey Secret, region, and security token based on the on-screen instructions.

    Enter the AccessKey ID that you created.

    Please enter Access Key ID:

    Enter the AccessKey secret that you created.

    Please enter Access Key Secret:

    Enter the region in which the bucket that stores your data is located. For example, if your bucket is located in the China (Hangzhou) region, enter cn-hangzhou.

    Please enter Region:

    Enter the security token. We recommend that you press the Enter key to leave the stsToken parameter empty.

    Please enter stsToken:
  5. Check whether ossutil is installed:

    ossutil

    If all commands supported by ossutil are displayed, ossutil is installed.

Step 3: Create a bucket

Run the following command to create a bucket named examplebucket:

ossutil mb oss://examplebucket

If the output is similar to the following content, the bucket is created.

0.668238(s) elapsed

Step 4: Upload an object

  1. Download the sample object named exampleobject.jpg to your local computer.

  2. Upload the downloaded sample object to the examplebucket bucket.

    ossutil cp exampleobject.jpg oss://examplebucket
    0.720812(s) elapsed

Step 5: Download an object

Run the following command to download the uploaded sample object named exampleobject.jpg from the examplebucket bucket to the localfolder directory in your computer:

ossutil cp oss://examplebucket/exampleobject.jpg localfolder/

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

0.154553(s) elapsed

Step 6: Share an object

Run the following command to generate a signed URL that has a validity period of 3,600 seconds for an object named oss://examplebucket/exampleobject.jpg:

ossutil sign oss://examplebucket/exampleobject.jpg --timeout 3600 

If the output is similar to the following content, the signed URL is generated.

https://examplebucket.oss-cn-hangzhou.aliyuncs.com/exampleobject.jpg?Expires=1608282224&OSSAccessKeyId=LTAI4G33piUmgRN1DXx9****&Signature=jo4%2FGykfuc1A4fvyvKRpRyymYH**** 0.368676(s) elapsed

Copy the signed URL to the address bar of your browser to access the object.

Step 7: Release resources

Alibaba Cloud OSS uses the pay-as-you-go billing method. Fees continue to be generated during the object retention period. To prevent additional fees from being generated for the uploaded objects, release the resources after the preceding operations are complete.

  • Delete an object

    Run the following command to delete the sample object named exampleobject.jpg from the examplebucket bucket:

    ossutil rm oss://examplebucket/exampleobject.jpg

    If the output is similar to the following content, the object is deleted.

    0.295530(s) elapsed
  • Delete a bucket

    Run the following command to delete an empty bucket named examplebucket:

    ossutil rb oss://examplebucket

    If the output is similar to the following content, the bucket is deleted.

    0.478659(s) elapsed

The preceding steps describe the basic usage of ossutil 1.0. For more information, see ossutil 1.0.