This topic describes commands related to objects.
osscmd was deprecated on July 31, 2019. Alibaba Cloud no longer maintains or updates osscmd. Its commands are integrated into ossutil. Use ossutil instead.
ls(list)
Command:
ls(list) oss://bucket/[prefix] [marker] [delimiter] [maxkeys]
Lists the objects in a bucket. You can specify a prefix to list all objects whose names start with the prefix. For example, if the prefix is abc, all objects whose names start with abc are listed.
Examples:
python osscmd ls oss://mybucket/folder1/folder2python osscmd ls oss://mybucket/folder1/folder2 marker1python osscmd ls oss://mybucket/folder1/folder2 marker1 /python osscmd ls oss://mybucket/python osscmd list oss://mybucket/ "" "" 100
Command:
ls(list) oss://bucket/[prefix] --marker=xxx --delimiter=xxx --maxkeys=xxx
--encoding_type=urlLists the objects in a bucket. The encoding_type parameter specifies the encoding method for object names in the response. If you set this parameter to url, objects that contain control characters in their names can be displayed.
Examples:
python osscmd ls oss://mybucket/folder1/folder2 --delimiter=/python osscmd ls oss://mybucket/folder1/folder2 --marker=apython osscmd ls oss://mybucket/folder1/folder2 --maxkeys=10
mkdir
Command:
mkdir oss://bucket/dirname
Creates a folder.
Example:
python osscmd mkdir oss://mybucket/folder
listallobject
Command:
listallobject oss://bucket/[prefix]
Lists all objects in a bucket. You can specify a prefix to list only the objects whose names start with the prefix.
Examples:
python osscmd listallobject oss://mybucketpython osscmd listallobject oss://mybucket/testfolder/
deleteallobject
Command:
deleteallobject oss://bucket/[prefix]
Deletes all objects in a bucket. You can specify a prefix to delete only the objects whose names start with the prefix.
Examples:
python osscmd deleteallobject oss://mybucketpython osscmd deleteallobject oss://mybucket/testfolder/
downloadallobject
Command:
downloadallobject oss://bucket/[prefix] localdir --replace=false
--thread_num=5Downloads objects from a bucket to a local directory and preserves the directory structure. You can specify a prefix to download only the objects whose names start with the prefix. If you set --replace to false, existing local files with the same names are not overwritten. If you set --replace to true, they are overwritten. You can also use thread_num to configure the number of download threads.
Examples:
python osscmd downloadallobject oss://mybucket /tmp/folderpython osscmd downloadallobject oss://mybucket /tmp/folder –-replace=falsepython osscmd downloadallobject oss://mybucket /tmp/folder –-replace=true --thread_num=5
downloadtodir
Command:
downloadtodir oss://bucket/[prefix] localdir --replace=false
Downloads objects from a bucket to a local directory and preserves the directory structure. You can specify a prefix to download only the objects whose names start with the prefix. If you set --replace to false, existing local files with the same names are not overwritten. If you set --replace to true, they are overwritten. The downloadtodir command works the same as the downloadallobject command.
Examples:
python osscmd downloadtodir oss://mybucket /tmp/folderpython osscmd downloadtodir oss://mybucket /tmp/folder –-replace=falsepython osscmd downloadtodir oss://mybucket /tmp/folder –-replace=true
uploadfromdir
Command:
uploadfromdir localdir oss://bucket/[prefix] --check_point=check_point_file --replace=false
--check_md5=false --thread_num=5Uploads files from a local directory to a bucket.
For example, if the local directory /tmp/ contains the files a/b, a/c, and a, the files are uploaded to oss://bucket/a/b, oss://bucket/a/c, and oss://bucket/a. If you specify the prefix as mytest, the files are uploaded to oss://bucket/mytest/a/b, oss://bucket/mytest/a/c, and oss://bucket/mytest/a.
The --check_point=check_point_file parameter specifies a checkpoint file. After you specify the file, osscmd stores the timestamps of uploaded local files in the checkpoint file. The uploadfromdir command then compares the timestamp of a file to be uploaded with the recorded timestamp in the checkpoint file. If the timestamp has changed, the file is re-uploaded. Otherwise, the upload is skipped. By default, no checkpoint file is used. If you set --replace to false, existing objects in the bucket with the same names are not overwritten. If you set it to true, they are overwritten. If you set --check_md5 to false, the Content-MD5 request header is not included and MD5 verification is not performed. If you set it to true, MD5 verification is performed.
Note: The checkpoint file records information about all uploaded files.
Examples:
python osscmd uploadfromdir /mytemp/folder oss://mybucketpython osscmd uploadfromdir /mytemp/folder oss://mybucket --check_point_file=/tmp/mytemp_record.txtpython osscmd uploadfromdir C:\Documents and Settings\User\My Documents\Downloads oss://mybucket --check_point_file=C:\cp.txt
put
Command:
put localfile oss://bucket/object --content-type=[content_type]
--headers="key1:value1#key2:value2" --check_md5=falseUploads a local file to a bucket. You can specify the content-type of the object or custom headers. If you set --check_md5 to false, the Content-MD5 request header is not included and MD5 verification is not performed. If you set it to true, MD5 verification is performed.
Examples:
python osscmd put myfile.txt oss://mybucketpython osscmd put myfile.txt oss://mybucket/myobject.txtpython 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:
upload localfile oss://bucket/object --content-type=[content_type]
--check_md5=falseYou can upload a local file as an Object group. This operation is not recommended. --check_md5=false disables verification of the Content-MD5 request header when you upload a file. If this parameter is set to true, the header is verified.
Example:
python osscmd upload myfile.txt oss://mybucket/test.txt
--content-type=plain/textget
Command:
get oss://bucket/object localfile
Downloads an object to a local file.
Example:
python osscmd get oss://mybucket/myobject /tmp/localfile
multiget(multi_get)
Command:
multiget(multi_get) oss://bucket/object localfile --thread_num=5
Downloads an object to a local file using multiple threads. You can configure the number of threads.
Examples:
python osscmd multiget oss://mybucket/myobject /tmp/localfilepython osscmd multi_get oss://mybucket/myobject /tmp/localfile
cat
Description:
cat oss://bucket/object
Reads and prints the content of an object. Do not use this command for large objects.
Example:
python osscmd cat oss://mybucket/myobject
meta
Command:
meta oss://bucket/object
Reads and prints the metadata of an object. The metadata includes the content-type, file length, and custom metadata.
Example:
python osscmd meta oss://mybucket/myobject
copy
Command:
copy oss://source_bucket/source_object oss://target_bucket/target_object
--headers="key1:value1#key2:value2"Copies a source object from a source bucket to a target object in a target bucket.
Example:
python osscmd copy oss://bucket1/object1 oss://bucket2/object2
rm(delete,del)
Command:
rm(delete,del) oss://bucket/object --encoding_type=url
Deletes an object. If you set encoding-type to url, the object name must also be URL-encoded.
Examples:
python osscmd rm oss://mybucket/myobjectpython osscmd delete oss://mybucket/myobjectpython osscmd del oss://mybucket/myobjectpython osscmd del oss://mybucket/my%01object --encoding_type=url
signurl(sign)
Command:
signurl(sign) oss://bucket/object --timeout=[timeout_seconds]
Generates a signed URL with a specified timeout period. This is useful for granting temporary access to a specific object in a private bucket.
Examples:
python osscmd sign oss://mybucket/myobjectpython osscmd signurl oss://mybucket/myobject