OSS Alibaba Cloud CLI command instructions

Last Updated: Feb 17, 2017

The following provides instructions and examples for OSS commands.

Config

Command Instructions:

Config --host oss.aliyuncs.com --accessid accessid --accesskey accesskey --sts_token token is used to configure the default host, ID, and Key of Alibaba Cloud CLI. The default host is oss.aliyuncs.com. To access oss-internal.aliyuncs.com, you can add host oss-internal.aliyuncs.com.

Example:

  1. aliyuncli oss Config --host oss.aliyuncs.com --accessid accessid --accesskey accesskey --sts_token token

GetAllBucket

Command Instructions:

GetAllBucket is used to display a bucket created by the user.

Example:

  1. aliyuncli oss GetAllBucket

CreateBucket

Command Instructions:

CreateBucket oss://bucket --acl [acl] oss://bucket is used to create a bucket, where oss://bucket indicates the bucket. The acl parameter can be included or excluded.

Examples:

  1. aliyuncli oss CreateBucket oss://myfirstbucket --acl public-read
  1. aliyuncli oss CreateBucket oss://mysecondbucket --acl private
  1. aliyuncli oss CreateBucket oss://mythirdbucket

DeleteBucket

Command Instructions:

DeleteBucket oss://bucket is used to delete a bucket.

Examples:

  1. aliyuncli oss DeleteBucket oss://mybucket
  1. aliyuncli oss DeleteBucket oss://myfirstbucket

DeleteWholeBucket

Danger: This command is very risky as it will erase all the data and the erased data cannot be recovered. Use it with caution.

Command Instructions:

DeleteWholeBucket oss://bucket is used to delete a bucket and its internal objects and multipart contents.

Example:

  1. aliyuncli oss DeleteWholeBucket oss://mybucket

GetAcl

Command Instructions:

GetAcl oss://bucketis used to get the ACL of a bucket.

Example:

  1. aliyuncli oss GetAcl oss://mybucket

SetAcl

Command Instructions:

SetAcl oss://bucket –acl [acl] is used to modify the ACL of a bucket. The ACL can only be one of the three: private, public-read, or public-read-write.

Example:

  1. aliyuncli oss SetAcl oss://mybucket --acl private

List

Command Instructions:

List oss://bucket/[prefix] [marker] [delimiter] [maxkeys] is used to list objects in a bucket.

Examples:

  1. aliyuncli oss List oss://mybucket/folder1/folder2
  1. aliyuncli oss List oss://mybucket/folder1/folder2 maker1

MkDir

Command Instructions:

MkDir oss://bucket/dirname is used to create an object ending with “/“ and with the size of 0.

Example:

  1. aliyuncli oss MkDir oss://mybucket/folder

ListAllObject

Command Instructions:

ListAllObject oss://bucket/[prefix] is used to display all objects in a bucket. The prefix can be specified for displaying objects.

Examples:

  1. aliyuncli oss ListAllObject oss://mybucket
  1. aliyuncli oss ListAllObject oss://mybucket/testfolder/

DeleteAllObject

Caution: This command is very risky as it will erase all the data and the erased data cannot be recovered. Use it with caution.

Command Instructions:

DeleteAllObject oss://bucket/[prefix] is used to delete all objects in a bucket. The prefix can be specified for deleting objects.

Examples:

  1. aliyuncli oss DeleteAllObject oss://mybucket
  1. aliyuncli oss DeleteAllObject oss://mybucket/testfolder/

DownloadAllObject

Command Instructions:

DownloadAllObject oss://bucket/[prefix] localdir --replace false is used to download all objects in a bucket to a local directory and keep the directory structure. The prefix can be specified for downloading. “replace false” indicates that if a local file with the same name already exists, it will not be overwritten during the downloading. “replace true” indicates that the local file with the same name will be overwritten.

Examples:

  1. aliyuncli oss DownloadAllObject oss://mybucket /tmp/folder
  1. aliyuncli oss DownloadAllObject oss://mybucket /tmp/folder --replace=false
  1. aliyuncli oss DownloadAllObject oss://mybucket /tmp/folder --replace=true

DownloadToDir

Command Instructions:

DownloadToDir oss://bucket/[prefix] localdir --replace=false is used to download all objects in a bucket to a local directory and keep the directory structure. The prefix can be specified for downloading. “replace=false” indicates that if a local file with the same name already exists, it will not be overwritten during the downloading. “replace=true” indicates that the local file with the same name will be overwritten. It achieves the same effect as downloadallobject.

Examples:

  1. aliyuncli oss DownloadToDir oss://mybucket /tmp/folder
  1. aliyuncli oss DownloadToDir oss://mybucket /tmp/folder --replace false
  1. aliyuncli oss DownloadToDir oss://mybucket /tmp/folder --replace true

UploadObjectFromLocalDir

Command Instructions:

UploadObjectFromLocalDir localdir oss://bucket/[prefix] --check_point check_point_file --replace false --check_md5 false --thread_num 5 is used to upload files from a local directory to a bucket. For example, if localdir is set to /tmp/ where three files are contained, namely a/b, a/c, and a, then the files will correspond to oss://bucket/a/b, oss://bucket/a/c, and oss://bucket/a after being uploaded to the OSS. If the prefix is set to mytest, then the files will correspond to oss://bucket/mytest/a/b, oss://bucket/mytest/a/c, and oss://bucket/mytest/a after being uploaded to the OSS. check_point check_point_file is to specify files. After files are specified, osscmd will put the uploaded local files into check_point_file as time stamps, and the uploadfromdir command will compare the time stamps of the files being uploaded with those recorded in check_point_file. If there are changes, the files will be re-uploaded. Otherwise, the files will be skipped. There is no check_point_file by default.

Note: Because the check_point_file records all uploaded files, when there are many uploaded files, the check_point_file could be sizable.

Examples:

  1. aliyuncli oss UploadObjectFromLocalDir /mytemp/folder oss://mybucket
  1. aliyuncli oss UploadObjectFromLocalDir /mytemp/folder oss://mybucket --check_point_file /tmp/mytemp_record.txt

Put

Command Instructions:

Put localfile oss://bucket/object --content-type [content_type]--headers "key1:value1,key2:value2" is used to upload a local file to a bucket. You can specify the content-type of the target object, or specify custom headers.

Examples:

  1. aliyuncli oss Put myfile.txt oss://mybucket
  1. aliyuncli oss Put myfile.txt oss://mybucket/myobject.txt
  1. aliyuncli oss Put myfile.txt oss://mybucket/test.txt --content-type plain/text --headers “x-oss-meta-des:test,x-oss-meta-location:CN”
  1. aliyuncli oss Put myfile.txt oss://mybucket/test.txt --content-type plain/text

Get

Command Instructions:

Get oss://bucket/object localfile is used to download an object to a local file.

Example:

  1. aliyuncli oss Get oss://mybucket/myobject /tmp/localfile

MultiGet

Command Instructions:

MultiGet oss://bucket/object localfile --thread_num 5 is used to download an object to a local file in the multi-thread way.

Examples:

  1. aliyuncli oss MultiGet oss://mybucket/myobject /tmp/localfile
  1. aliyuncli oss MultiGet oss://mybucket/myobject /tmp/localfile

Cat

Command Instructions:

Cat oss://bucket/object is used to read and directly print the content of an object. Do not use it when the object content is too big in size.

Example:

  1. aliyuncli oss Cat oss://mybucket/myobject

Meta

Command Instructions:

Meta oss://bucket/object is used to read and print the meta information of an object. The meta information includes content-type, file length, custom meta, and so on.

Example:

  1. aliyuncli oss Meta oss://mybucket/myobject

Copy

Command Instructions:

Copy oss://source_bucket/source_object oss://target_bucket/target_object --headers="key1:value1,key2:value2" is used to copy a source object from the source bucket to a target object in the target bucket.

Example:

  1. aliyuncli oss Copy oss://bucket1/object1 oss://bucket2/object2

Delete

Command Instructions:

Delete oss://bucket/object is used to delete an object.

Example:

  1. aliyuncli oss Delete oss://mybucket/myobject

SignUrl

Command Instructions:

SignUrl oss://bucket/object --timeout [timeout_seconds] is used to generate a URL containing signature, and specify the timeout duration. This command is applicable when specified objects in a private bucket are provided for others to access.

Example:

  1. aliyuncli oss SignUrl oss://mybucket/myobject

Init

Command Instructions:

Init oss://bucket/object is used to initialize an Upload ID. This Upload ID can be used together with the MultiUpload command.

Example:

  1. aliyuncli oss Init oss://mybucket/myobject

ListPart

Command Instructions:

ListPart oss://bucket/object --upload_id xxx is used to Display the uploaded parts under the Upload ID of the specified object. See OSS API documentation for related concepts. The Upload ID must be specified.

Example:

  1. aliyuncli oss ListPart oss://mybucket/myobject --upload_id 75835E389EA648C0B93571B6A46023F3

ListParts

Command Instructions:

ListParts oss://bucke is used to display the incompleted multipart Upload ID and objects in a bucket. If the system prompts that a bucket is not empty when you are trying to delete it, you can use this command to check whether there are multi-part contents.

Example:

  1. aliyuncli oss ListParts oss://mybucket

GetAllPartSize

Command Instructions:

GetAllPartSize oss://bucket is used to display the total size of parts in a bucket that are uploaded with the Upload ID.

Example:

  1. aliyuncli oss GetAllPartSize oss://mybucket

Cancel

Command Instructions:

Cancel oss://bucket/object --upload_id xxx is used to terminate the Multipart Upload event corresponding to the Upload ID.

Example:

  1. aliyuncli oss Cancel oss://mybucket/myobject --upload_id D9D278DB6F8845E9AFE797DD235DC576

MultiUpload

Command Instructions (a):

MultiUpload localfile oss://bucket/object is used to upload a local file to the OSS in the multipart way.

Example:

  1. aliyuncli oss MultiUpload /tmp/localfile.txt oss://mybucket/object

Command Instructions (b):

MultiUpload localfile oss://bucket/object --upload_id xxx --thread_num 10 --max_part_num 1000 is used to upload a local file to the OSS in the multipart way. The number of divided parts of the local file is specified by max_part_num. This command will first determine whether the ETag of the corresponding parts of the Upload ID is consistent with the MD5 value of the local file. If yes, the upload will be skipped. So if an Upload ID is generated before use, it will be included as a parameter. Even if the upload fails, the upload can be resumed by executing the same multiupload command.

Examples:

  1. aliyuncli oss MultiUpload /tmp/localfile.txt oss://mybucket/object --upload_id D9D278DB6F8845E9AFE797DD235DC576
  1. aliyuncli oss MultiUpload /tmp/localfile.txt oss://mybucket/object --thread_num 5
  1. aliyuncli oss MultiUpload /tmp/localfile.txt oss://mybucket/object --max_part_num 100

UploadPartFromFile

Command Instructions:

UploadPartFromFile localfile oss://bucket/object --upload_id xx --part_number xxx is mainly used for testing and is not recommended.

UploadPartFromString

Command Instructions:

UploadPartFromString oss://bucket/object --upload_id xxx --part_number xxx --data xxx is mainly used for testing and is not recommended.

Thank you! We've received your feedback.