Object commands

Last Updated: Oct 31, 2016

ls(list)

Command instructions:

ls(list) oss://bucket/[prefix] [marker] [delimiter] [maxkeys]

List object in the bucket.

Example:

  • python osscmd ls oss://mybucket/folder1/folder2
  • python osscmd ls oss://mybucket/folder1/folder2 maker1
  • python osscmd ls oss://mybucket/folder1/folder2 maker1 /
  • python osscmd ls oss://mybucket/
  • python osscmd list oss://mybucket/ "" "" 100

Command instructions:

ls(list) oss://bucket/[prefix] --marker=xxx --delimiter=xxx --maxkeys=xxx

List object in the bucket.

Example:

  • python osscmd ls oss://mybucket/folder1/folder2 --delimiter=/
  • python osscmd ls oss://mybucket/folder1/folder2 --maker=a
  • python osscmd ls oss://mybucket/folder1/folder2 --maxkeys=10

mkdir

Command instructions:

mkdir oss://bucket/dirname

Create an object ending with “/” of a size of 0.

Example:

  • python osscmd mkdir oss://mybucket/folder

listallobject

Command instructions:

listallobject oss://bucket/[prefix]

Show all objects in the bucket, and the prefix can be specified.

Example:

  • python osscmd listallobject oss://mybucket
  • python osscmd listallobject oss://mybucket/testfolder/

deleteallobject

Command instructions:

deleteallobject oss://bucket/[prefix]

Delete all objects in the bucket, and the prefix can be specified.

Example:

  • python osscmd deleteallobject oss://mybucket
  • python osscmd deleteallobject oss://mybucket/testfolder/

downloadallobject

Command instructions:

downloadallobject oss://bucket/[prefix] localdir --replace=false --thread_num=5

Download the objects in the bucket to a local directory, with the directory structure unchanged. The prefix can be specified for downloading. —replace=false indicates that if a local file already exists with the same name, it will not be replaced during the download. —replace=true indicates that the local file with the same name will be replaced. The thread_num can be used to configure the download threading.

Example:

  • python osscmd downloadallobject oss://mybucket /tmp/folder
  • python osscmd downloadallobject oss://mybucket /tmp/folder –-replace=false
  • python osscmd downloadallobject oss://mybucket /tmp/folder –-replace=true --thread_num=5

downloadtodir

Command instructions:

downloadallobject oss://bucket/[prefix] localdir --replace=false

Download the objects in the bucket to a local directory, with the directory structure unchanged. The prefix can be specified for downloading. —replace=false indicates that if a local file already exists with the same name, it will not be replaced during the download. —replace=true indicates that the local file with the same name will be replaced. It achieves the same effect with the downloadallobject.

Example:

  • python osscmd downloadtodir oss://mybucket /tmp/folder
  • python osscmd downloadtodir oss://mybucket /tmp/folder –-replace=false
  • python osscmd downloadtodir oss://mybucket /tmp/folder –-replace=true

uploadfromdir

Command instructions:

uploadfromdir localdir oss://bucket/[prefix] --check_point=check_point_file --replace=false --check_md5=false --thread_num=5

Upload local files into the bucket. E.g., the localdir is /tmp/

There are three files a/b, a/c, and a, and they will be oss://bucket/a/b, oss://bucket/a/c, oss://bucket/a after being uploaded into the OSS. If the prefix is specified as mytest, the uploaded files to OSS will be oss://bucket/mytest/a/b, oss://bucket/mytest/a/c, and oss://bucket/mytest/a.

--check_point=check_point_file is the specified file. After the 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 that recorded in check_point_file. If there are changes, the files will be re-uploaded. Otherwise the file will be skipped. The check_point_file does not exist by default. --replace=false indicates that if a local file already exists with the same name, it will not be replaced during the download. —replace=true indicates that the local file with the same name will be replaced. --check_md5=false indicates that when the files are being uploaded, the Content-MD5 request header will not undergo verification. True indicates that the Content-MD5 request header will undergo verification.

Note: the logs in the check_point_file involve all the uploaded files. When there are too many files uploaded, the check_point_file will be sizable.

Example:

  • python osscmd uploadfromdir /mytemp/folder oss://mybucket
  • python osscmd uploadfromdir /mytemp/folder oss://mybucket --check_point_file=/tmp/mytemp_record.txt
  • python osscmd uploadfromdir C:\Documents and Settings\User\My Documents\Downloads oss://mybucket --check_point_file=C:\cp.txt

put

Command instructions:

put localfile oss://bucket/object --content-type=[content_type] --headers="key1:value1#key2:value2" --check_md5=false

When uploading a local file into the bucket, you can specify the object content-type, or specify customized headers. --check_md5=false indicates that when the files are being uploaded, the Content-MD5 request header will not undergo verification. True indicates that the Content-MD5 request header will undergo verification.

Example:

  • python osscmd put myfile.txt oss://mybucket
  • python osscmd put myfile.txt oss://mybucket/myobject.txt
  • python osscmd put myfile.txt oss://mybucket/test.txt --content-type=plain/text --headers=“x-oss-meta-des:test#x-oss-meta-location:CN”
  • python osscmd put myfile.txt oss://mybucket/test.txt --content-type=plain/text

upload

Command instructions:

upload localfile oss://bucket/object --content-type=[content_type] --check_md5=false

Upload local files in object group. Not recommended. --check_md5=false indicates that when the files are being uploaded, the Content-MD5 request header will not undergo verification. True indicates that the Content-MD5 request header will undergo verification.

Example:

  • python osscmd upload myfile.txt oss://mybucket/test.txt --content-type=plain/text

get

Command Instructions:

get oss://bucket/object localfile

Download the object to local.

Example:

  • python osscmd get oss://mybucket/myobject /tmp/localfile

multiget(multi_get)

Command instructions:

multiget(multi_get) oss://bucket/object localfile --thread_num=5

Download the object to local in multithreading. The thread count can be configured.

Example:

  • python osscmd multiget oss://mybucket/myobject /tmp/localfile
  • python osscmd multi_get oss://mybucket/myobject /tmp/localfile

cat

Command instructions:

cat oss://bucket/object

Read object content and print them out directly. Do not use it when the object content is big in size.

Example:

  • python osscmd cat oss://mybucket/myobject

meta

Command instructions:

meta oss://bucket/object

Read the meta information of the object and print it out. The meta information includes the content-type, file length, custom meta, etc.

Example:

  • python osscmd meta oss://mybucket/myobject

copy

Command instructions:

copy oss://source_bucket/source_object oss://target_bucket/target_object --headers="key1:value1#key2:value2"

Copy the source object of the source bucket to the destination object in the destination bucket.

Example:

  • python osscmd copy oss://bucket1/object1 oss://bucket2/object2

rm(delete,del)

Command instructions:

rm(delete,del) oss://bucket/object

Delete object.

Example:

  • python osscmd rm oss://mybucket/myobject
  • python osscmd delete oss://mybucket/myobject
  • python osscmd del oss://mybucket/myobject

signurl(sign)

Command instructions:

signurl(sign) oss://bucket/object --timeout=[timeout_seconds]

Generate a URL containing the signature and specify the timeout value. This is applicable to the scenario where the private bucket provides the specified object for others’ accesses.

Example:

  • python osscmd sign oss://mybucket/myobject
  • python osscmd signurl oss://mybucket/myobject
Thank you! We've received your feedback.