tencent cloud

Cloud Object Storage

COSCMD

Download
Mode fokus
Ukuran font
Terakhir diperbarui: 2026-07-15 10:48:49

Feature Overview

Using the COSCMD tool, users can perform operations such as batch uploading, downloading, and deleting objects through simple command line instructions.

Usage Environment

System environment

Supports Windows, Linux and macOS systems.
Note:
Ensure that the local character encoding is set to UTF-8. Otherwise, operations on Chinese version files will cause exceptions.
Please make sure that the time of this machine has been calibrated with the international standard time. If the error is too large, it will not work properly.

Software Dependency

Python 2.7 and Python 3.
The latest version of pip.
Note:
It is recommended that users directly install a Python version with pip integrated.
When the Python version is 3.12, pip installation of dependency libraries is prone to failure. It is recommended to use source code installation.

Installation Configuration

For detailed instructions on environment installation and configuration, see Python Installation and Configuration.
For detailed instructions on pip environment installation and configuration, please refer to Official PIP Installation Instructions.

Download and Installation

The following three methods are provided for users to install COSCMD.

Method 1: Installing via pip (Recommended)

1. Execute the following pip command to install.
pip install coscmd
After successful installation, users can view the current version information using the -v or --version command.
Attention:
After installing with Windows, you need to add the two paths, C:\\python_install_dir and C:\\python_install_dir\\Scripts, to the environment variables.
2. After installation is complete, run the following command to update.
pip install coscmd -U

Method 2: Installing from Source

Attention:
When the Python version is 3.12, pip installation of dependency libraries is prone to failure. It is recommended to use this method for installation.
Source code download address: Click here.
git clone https://github.com/tencentyun/coscmd.git
cd coscmd
python setup.py install

Method 3: Offline Installation

Attention:
If your target machine cannot be installed online, you can first download the offline installation package on a machine with network access. Then, copy the offline installation package to the target machine without network access for installation.
Ensure that the two machines are installed with the same version of Python. Otherwise, the installation may fail.
# Run the following command on a machine with external network
mkdir coscmd-packages
pip download coscmd -d coscmd-packages
tar -czvf coscmd-packages.tar.gz coscmd-packages

# Copy the installation package to a machine without external network and run the following command
tar -xzvf coscmd-packages.tar.gz
pip install coscmd --no-index -f coscmd-packages

Parameter

Viewing the help Option

Users can view the tool's help information and usage by using the -h or --help command.
coscmd -h
The help information is as follows:
usage: coscmd [-h] [-d] [-s] [-b BUCKET] [-r REGION] [-c CONFIG_PATH]
[-l LOG_PATH] [--log_size LOG_SIZE]
[--log_backup_count LOG_BACKUP_COUNT] [-v]
{config,upload,download,delete,abort,copy,move,list,listparts,info,restore,signurl,createbucket,deletebucket,putobjectacl,getobjectacl,putbucketacl,getbucketacl,putbucketversioning,getbucketversioning,probe}
...

an easy-to-use but powerful command-line tool. try 'coscmd -h' to get more
informations. try 'coscmd sub-command -h' to learn all command usage, likes
'coscmd upload -h'

positional arguments:
{config,upload,download,delete,abort,copy,move,list,listparts,info,restore,signurl,createbucket,deletebucket,putobjectacl,getobjectacl,putbucketacl,getbucketacl,putbucketversioning,getbucketversioning,probe}
config Config your information at first
upload Upload file or directory to COS
download Download file from COS to local
delete Delete file or files on COS
abort Aborts upload parts on COS
copy Copy file from COS to COS
move move file from COS to COS
list List files on COS
listparts List upload parts
info Get the information of file on COS
restore Restore
signurl Get download url
createbucket Create bucket
deletebucket Delete bucket
putobjectacl Set object acl
getobjectacl Get object acl
putbucketacl Set bucket acl
getbucketacl Get bucket acl
putbucketversioning
Set the versioning state
getbucketversioning
Get the versioning state
probe Connection test

optional arguments:
-h, --help show this help message and exit
-d, --debug Debug mode
-s, --silence Silence mode
-b BUCKET, --bucket BUCKET
Specify bucket
-r REGION, --region REGION
Specify region
-c CONFIG_PATH, --config_path CONFIG_PATH
Specify config_path
-l LOG_PATH, --log_path LOG_PATH
Specify log_path
--log_size LOG_SIZE specify max log size in MB (default 1MB)
--log_backup_count LOG_BACKUP_COUNT
specify log backup num
-v, --version show program's version number and exit
In addition, users can also enter -h after each command (without parameters) to view the specific usage of that command, as shown below.
# View the usage of the upload command
coscmd upload -h

Generating a Configuration File Using the config Command

Attention:
It is recommended that users use the tool with temporary credentials to enhance security through temporary authorization. When applying for temporary credentials, follow the principle of least privilege to prevent the leakage of resources beyond the target bucket or object.
If you must use permanent credentials, it is recommended to follow the principle of least privilege to restrict the permission scope of the permanent credentials.
The config command can automatically generate a configuration file at ~/.cos.conf. The specific command format is as follows.
coscmd config [OPTION]...<FILE>...
[-h] --help
[-a] <SECRET_ID>
[-s] <SECRET_KEY>
[-t] <TOKEN>
[-b] <BucketName-APPID>
[-r] <REGION> | [-e] <ENDPOINT>
[-m] <MAX_THREAD>
[-p] <PART_SIZE>
[--do-not-use-ssl]
[--anonymous]
Note:
The fields in "[]" are options, and the fields in "<>" are parameters that need to be filled in.
The parameter configuration is described below.
Option
Description
Effective value
Required
-a
To obtain the Secret ID, go to the API Key Console.
String
Yes
-s
To obtain the Secret Key, go to the API Key Console.
String
Yes
-t
Configure the temporary key token and set the x-cos-security-token header when using a temporary key.
String
No
-b
Specify the bucket name. The naming format for a bucket is BucketName-APPID. For details, see Naming Conventions. For initial configuration and use, you need to create a bucket in the COS console for configuring the tool.
String
Yes
-r
For the bucket region, see Regions and Access Domains.
String
Yes
-e
Set the request ENDPOINT. After the ENDPOINT parameter is set, the REGION parameter becomes invalid. If you use the default domain name, configure the format here as cos.<region>.myqcloud.com. If you use the global acceleration domain name, configure it as cos.accelerate.myqcloud.com.
String
No
-m
Specify the maximum number of threads for multi-threaded operations (default is 5). If file uploads are slow, you can appropriately increase this value. The number of threads depends on machine performance. Assuming the machine supports a maximum of 30 threads, adjust the concurrent threads to 30 to fully utilize machine performance. Run the command coscmd config -m 30.
Numeric
No
-p
The chunk size for chunked operations (unit: MB, default: 1 MB, range: 1 - 1000). If file uploads are slow, you can appropriately increase this value.
Numeric
No
--do-not-use-ssl
Use the HTTP protocol instead of HTTPS.
String
No
--anonymous
Anonymous operation (without carrying a signature).
String
No
The usage example of the config command is as follows:
coscmd config -a AChT4ThiXAbpBDEFGhT4ThiXAbp**** -s WE54wreefvds3462refgwewe**** -b configure-bucket-1250000000 -r ap-chengdu

Generating a Configuration File

The COSCMD tool reads the required information from a configuration file during runtime. By default, the configuration file path read by COSCMD is ~/.cos.conf. To change the configuration file path, see the command for specifying configuration and log file paths.
Note:
Before configuration, you need to create a bucket for storing configuration parameters (for example, configure-bucket-1250000000) in the COS console. See Create Bucket. Then, create access key information. See Root Account Access Key Management.
An example of a configuration file is shown below.
[common]
secret_id = ************************************
secret_key = ************************************
bucket = configure-bucket-1250000000
region = ap-chengdu
max_thread = 5
part_size = 1
retry = 5
timeout = 60
schema = https
verify = md5
anonymous = False
Note:
In the configuration file, the timeout item, measured in seconds, specifies the timeout duration for data read and write operations.
In the configuration file, the schema item can be set to either http or https, with https being the default.
In the configuration file, the anonymous item can be set to True or False, indicating whether to use anonymous mode, which means keeping the signature empty.
For more information on configuration parameters, use the command coscmd config -h.

Common Commands

Commands for specifying Bucket and Region

If a user runs a command without specifying the bucket name and region, the command is effective for the bucket configured in the parameters by default. To perform operations on different buckets, you need to specify the bucket name and region.
Note:
Specify the bucket name using the -b <BucketName-APPID> parameter. The bucket naming format is BucketName-APPID, and the bucket name entered here must follow this format.
You can specify the bucket's region using -r <region>.
Command format.
coscmd -b <BucketName-APPID> -r <region> <action> ...
Operation example: Create a bucket named examplebucket-1250000000 in the Beijing region.
coscmd -b examplebucket-1250000000 -r ap-beijing createbucket
Operation example: Upload the file picture.jpg from the D drive to the bucket named examplebucket-1250000000.
coscmd -b examplebucket-1250000000 -r ap-beijing upload D:/picture.jpg /

Commands for Specifying Configuration and Log File Paths

If a user does not specify the configuration file path, the default configuration file path ~/.cos.conf is used. If the log file path is not specified, the default log file path ~/.cos.log is used.
Note:
Specify the configuration file path using the -c <conf_path> parameter. COSCMD reads the configuration information from this path during runtime.
Specify the log path using the -l <log_conf> parameter. COSCMD outputs the logs generated during runtime to the log file under this path.
Command format.
coscmd -c <conf_path> -l <log_conf> <action> ...
Operation example: Specify the configuration file path as /data/home/cos_conf and the log output path as /data/home/cos_log, then create a bucket named examplebucket-1250000000 in the Beijing region.
coscmd -c /data/home/cos_conf -l /data/home/cos_log -b examplebucket-1250000000 -r ap-beijing createbucket

Executing Command in Debug Mode

Add -d or --debug before each command. During command execution, detailed operation information is displayed, as shown in the following example.
Command format.
coscmd -d upload <localpath> <cospath>
Operation example: Detailed information is output during upload.
coscmd -d upload -rs D:/folder/ /

Running Command in Silence Mode

Add -s or --silence before each command. During command execution, no information is output.
Note:
This command requires a minimum version of 1.8.6.24.
Command format.
coscmd -s upload <localpath> <cospath>
Operation example.
coscmd -s upload D:/picture.jpg /

Common Bucket Commands

Creating a Bucket

Note:
When executing the command to create a bucket, include the parameter -b <BucketName-APPID> to specify the bucket name and -r <Region> to specify the region. If you run coscmd createbucket directly, an error occurs. This is because omitting the bucket name and region is equivalent to attempting to create the existing bucket (that is, the bucket specified during configuration).
Command format.
coscmd -b <BucketName-APPID> createbucket
Operation example: Create a bucket named examplebucket-1250000000 in the Beijing region.
coscmd -b examplebucket-1250000000 -r ap-beijing createbucket

Deleting a Bucket

Note:
The usage of coscmd deletebucket is valid only for the bucket specified during configuration. It is recommended to use it with -b <BucketName-APPID> to specify the Bucket and -r <region> to specify the Region.
Command format.
coscmd -b <BucketName-APPID> deletebucket
Operation example: Delete an empty bucket.
coscmd -b examplebucket-1250000000 -r ap-beijing deletebucket
Operation example: Force delete a non-empty bucket.
coscmd -b examplebucket-1250000000 -r ap-beijing deletebucket -f
Attention:
Using the -f parameter forces deletion of the bucket, including all files, historical folders after versioning is enabled, and upload fragments. Proceed with caution.

Common Object Commands

Uploading Documents

Command format.
coscmd upload <localpath> <cospath>
Attention:
Replace the parameters enclosed in "<>" with the path of the local file (localpath) to upload and the COS storage path (cospath).
COSCMD does not support uploading symbolic links. Use the COSCLI tool instead. For details, see Upload, Download, or Copy Files - cp.
Operation example: Upload the picture.jpg file from the D drive to the doc directory in COS.
coscmd upload D:/picture.jpg doc/
Operation example: Upload the picture.jpg file from the doc folder on the D drive to the doc directory in COS.
coscmd upload D:/doc/picture.jpg doc/
Operation example: Specify the object type and upload an archive-type file to the doc directory in COS.
coscmd upload D:/picture.jpg doc/ -H "{'x-cos-storage-class':'Archive'}"
Attention:
When using the -H parameter to set the HTTP header, ensure the format is JSON. Example: coscmd upload -H "{'x-cos-storage-class':'Archive','Content-Language':'zh-CN'}" <localpath> <cospath>. For more headers, see the PUT Object document.
Operation example: Set the meta attribute and upload a file to the doc directory in COS.
coscmd upload D:/picture.jpg doc/ -H "{'x-cos-meta-example':'example'}"
Operation example: Specify an upload speed limit of 800 Kb/s and upload the file.zip file from the doc folder on the D drive to the doc directory in COS.
coscmd upload D:/doc/file.zip doc/ -H "{'x-cos-traffic-limit':'819200'}"
Note:
Use the -H parameter to specify the request header x-cos-traffic-limit for rate limiting. The rate limit value must be between 819200 and 838860800. The unit defaults to bit/s, which is 800 Kb/s to 800 Mb/s. If the value exceeds this range, a 400 error is returned.

Uploading Folders

Command format.
coscmd upload -r <localpath> <cospath>
Attention:
For Windows users, it is recommended to use the COSCMD upload command in the system's built-in cmd tool or PowerShell. Other tools, such as git bash, have different command path parsing policies than PowerShell, which may cause user files to be uploaded to incorrect paths.
Operation example: Upload the doc folder and its files from the D drive to the COS root path.
coscmd upload -r D:/doc /
Operation example: Upload the files and subfolders from the doc folder on the D drive to the test path in COS, excluding the doc folder itself.
coscmd upload -r D:/doc test
Operation example: Perform a sync upload, skipping files with the same name that have identical md5 values and file sizes.
coscmd upload -rs D:/doc doc
Attention:
Use the -s parameter to perform a sync upload, skipping files with matching md5 values (the prerequisite is that the original file on COS must have been uploaded by COSCMD version 1.8.3.2 or later, which by default includes the x-cos-meta-md5 header).
Operation example: Perform a sync upload, skipping files with the same name that have identical file sizes.
coscmd upload -rs --skipmd5 D:/doc doc
Attention:
Use the -s parameter to perform a sync upload. When the --skipmd5 parameter is also specified, only the file sizes of files with the same name are compared, and uploads are skipped if the sizes are identical.
Operation example: Perform a sync upload and delete the files that have been deleted from the doc folder on the D drive.
coscmd upload -rs --delete D:/doc /
Note:
For example, on a given day, the files in the doc folder on the D drive have been synced and uploaded to the doc path in COS, making the source and target consistent. The next day, if the user deletes file A from the doc folder on the D drive, executing the above command at that point will delete file A from the doc path in COS. This ultimately ensures that the files in the doc folder on the D drive remain consistent with the files in the doc path in COS.
Operation example: Selectively skip uploading files with .txt and .doc extensions from the doc folder on the D drive.
coscmd upload -rs D:/doc / --ignore *.txt,*.doc
Operation example: Selectively skip uploading files with the .txt extension from the doc folder on the D drive.
coscmd upload -rs D:/doc / --ignore "*.txt"
Attention:
When uploading a folder, use the --ignore parameter to exclude a specific type of file, and use the --include parameter to filter for a specific type of file. shell wildcard patterns are supported, and multiple rules can be specified, separated by commas ,. When a file type is excluded by its suffix, the suffix must be enclosed in "".
If you want to use the --ignore parameter to exclude all files within a specific folder, you must use an absolute path and enclose the path in "". For example: coscmd upload -rs D:/doc / --ignore "D:/doc/ignore_folder/*".
Operation example: Upload files with .txt and .doc extensions from the doc folder on the D drive.
coscmd upload -rs D:/doc / --include *.txt,*.doc
Operation example: Upload files with the .txt extension from the doc folder on the D drive.
coscmd upload -rs D:/doc / --include "*.txt"
Attention:
When a file larger than a certain threshold (100 MB) is uploaded, COSCMD uses the multipart upload method. The command syntax is the same as for a simple upload, which is coscmd upload <localpath> <cospath>. If you are using a version earlier than 1.8.6.31 (excluding version 1.8.6.31), this threshold is 10 MB.
COSCMD supports the feature of resumable upload for large files. If a multipart upload of a large file fails, re-uploading the file will only upload the failed parts instead of starting from the beginning. Ensure that the directory and content of the file being re-uploaded remain consistent with those of the original upload.
COSCMD performs an MD5 check on each part during a multipart upload.
By default, COSCMD uploads include the x-cos-meta-md5 header, whose value is the md5 of the file. If the --skipmd5 parameter is used, this header is not included.

Query file list

The query command is as follows:
Command format.
coscmd list <cospath>
Operation example: Recursively query all file lists under the doc/ prefix in the bucket.
coscmd list doc/
Operation example: Recursively query all file lists, file counts, and file sizes in the bucket.
coscmd list -ar
Operation example: Recursively query all file lists with the examplefolder prefix.
coscmd list examplefolder/ -ar
Operation example: Query the historical versions of all files in the bucket.
coscmd list -v
Note:
Replace the parameters enclosed in "<>" with the COS path (cospath) of the file for which you need to query the file list. If <cospath> is empty, the root directory of the current bucket is queried by default.
Use -a to query all files.
Use -r for recursive querying, which returns the total number and size of the listed files at the end.
Use -n num to set the maximum value for the query quantity.

Viewing File Information

The command is as follows:
Command format.
coscmd info <cospath>
Operation example: View the metadata of doc/picture.jpg.
coscmd info doc/picture.jpg
Note:
Replace the parameters enclosed in "<>" with the COS path (cospath) of the file to display.

Download a file or folder

Downloading a File

Command format.
coscmd download <cospath> <localpath>
Attention:
Replace the parameters enclosed in "<>" with the COS path (cospath) of the file to download and the local storage path (localpath).
Operation example: Download doc/picture.jpg from COS to D:/picture.jpg.
coscmd download doc/picture.jpg D:/picture.jpg
Operation example: Download doc/picture.jpg from COS to the D drive.
coscmd download doc/picture.jpg D:/
Operation example: Download a picture.jpg file with a version ID to the D drive.
coscmd download picture.jpg --versionId MTg0NDUxMzc2OTM4NTExNTg7Tjg D:/
Operation example: Specify a single-link download speed limit of 800 Kb/s and download doc/picture.jpg from COS to D:/picture.jpg.
coscmd download doc/picture.jpg D:/picture.jpg -H "{'x-cos-traffic-limit':'819200'}"
Note:
To apply rate limiting, specify the request header x-cos-traffic-limit using the -H parameter. The rate limit value must be between 819200 and 838860800. The unit defaults to bit/s, which is 800 Kb/s to 800 Mb/s. If the value exceeds this range, a 400 error is returned.

Downloading a Folder

Command format.
coscmd download -r <cospath> <localpath>
Operation example: Download the doc directory to D:/folder/doc.
coscmd download -r doc D:/folder/
Operation example: Download files from the root directory, but skip the doc directory under the root directory.
coscmd download -r / D:/ --ignore "doc/*"
Operation example: Overwrite and download all files in the root directory of the current bucket.
coscmd download -rf / D:/examplefolder/
Attention:
If a file with the same name exists locally, the download will fail. Use the -f parameter to overwrite the local file.
Operation example: Perform a sync download of all files in the root directory of the current bucket, skipping files with the same name that have identical md5 checksums.
coscmd download -rs / D:/examplefolder
Attention:
Use -s or --sync parameters, you can skip the same files that already exist locally when downloading a folder (the premise is that the downloaded file is uploaded through the COSCMD upload interface, and the file carries x-cos-meta-md5 head).
Operation example: Perform a sync download of all files in the root directory of the current bucket, skipping files with the same name and identical file size.
coscmd download -rs --skipmd5 / D:/examplefolder
Operation example: Perform a sync download and delete the files that have been deleted from the doc path in the COS bucket.
coscmd download -rs --delete / D:/doc
Note:
For example, on a given day, the files in the doc folder on the D drive have been synced and downloaded from the doc path in COS, making the source and target consistent. The next day, if the user deletes file A from the doc path in COS, executing the above command and entering y (confirm) as prompted by the window will delete file A from the doc folder on the D drive. This ultimately ensures that the files in the doc folder on the D drive remain consistent with the files in the doc path in COS.
Operation example: Skip files with .txt and .doc extensions.
coscmd download -rs / D:/examplefolder --ignore *.txt,*.doc
Operation example: Skip files with the .txt extension.
coscmd download -rs / D:/examplefolder --ignore "*.txt"
Attention:
When uploading a folder, you can use the --ignore parameter to exclude a specific type of file, and the --include parameter to filter for a specific type of file. The parameters support shell wildcard patterns and multiple rules, which are separated by commas ,. When excluding a file type by its suffix, you must enclose the suffix in "".
If you want to use the --ignore parameter to exclude all files within a specific directory, you must use an absolute path and enclose the path in "". For example: coscmd upload -rs D:/doc / --ignore "D:/doc/ignore_folder/*".
Operation example: Filter files with .txt and .doc extensions.
coscmd download -rs / D:/examplefolder --include *.txt,*.doc
Operation example: Filter files with the .txt extension.
coscmd download -rs / D:/examplefolder --include "*.txt"
Attention:
The old version of mget interface has been abolished. The download interface uses part downloading. Please use the download interface.

Get the signed download URL

Command format.
coscmd signurl <cospath>
Operation example: Generate a signed URL for the doc/picture.jpg path.
coscmd signurl doc/picture.jpg
Operation example: Generate a signed URL with a 100-second validity period for the doc/picture.jpg path.
coscmd signurl doc/picture.jpg -t 100
Note:
Replace the parameter enclosed in "<>" with the COS path (cospath) of the file for which you need to obtain the download URL.
Use -t time to set the validity period (in seconds) for the signature in the URL. The default is 10000s.

Deleting a file or folder

Deletes files

Command format.
coscmd delete <cospath>
Attention:
Replace the parameter enclosed in "<>" with the COS path (cospath) of the file you need to delete. The tool will then prompt you to confirm the deletion.
Operation example: Delete doc/exampleobject.txt.
coscmd delete doc/exampleobject.txt
Operation example: Delete the file with a version ID.
coscmd delete doc/exampleobject.txt --versionId MTg0NDUxMzc4ODA3NTgyMTErEWN

Deleting a Folder

Command format.
coscmd delete -r <cospath>
Operation example: Delete the doc directory.
coscmd delete -r doc
Operation example: Delete the folder/doc directory.
coscmd delete -r folder/doc
Operation example: Delete all version control files in the doc folder.
coscmd delete -r doc/ --versions
Note:
For batch deletion, you must enter y to confirm. Using the -f parameter allows you to skip the confirmation and delete directly.
Note that executing the command to delete a folder will remove the current folder and its files. However, to delete a version-controlled file, you must specify its version ID.

Viewing incomplete multipart uploads

Command format.
coscmd listparts <cospath>
Operation example: Query file fragments with the doc/ prefix.
coscmd listparts doc/

Aborting incomplete multipart uploads

Command format.
coscmd abort
Operation example: Eliminate all uploaded file fragments.
coscmd abort

Copy a file or folder

Copy a file

Command format.
coscmd copy <sourcepath> <cospath>
Operation example: Copy the picture.jpg file from the examplebucket-1250000000 bucket to the doc folder within the same bucket.
coscmd -b examplebucket-1250000000 -r ap-chengdu copy examplebucket-1250000000.cos.ap-chengdu.myqcloud.com/picture.jpg doc/
Operation example: Copy the doc/picture.jpg object from the examplebucket2-1250000000 bucket to the doc/examplefolder/ directory in the examplebucket1-1250000000 bucket.
coscmd -b examplebucket1-1250000000 -r ap-guangzhou copy examplebucket2-1250000000.cos.ap-beijing.myqcloud.com/doc/picture.jpg doc/examplefolder/
Modify the storage type, changing the storage type of the copied object to STANDARD_IA.
coscmd -b examplebucket1-1250000000 -r ap-guangzhou copy examplebucket2-1250000000.cos.ap-beijing.myqcloud.com/doc/picture.jpg doc/examplefolder/ -H "{'x-cos-storage-class':'STANDARD_IA'}"
Modify the storage type, changing the storage type of the copied object to ARCHIVE, and rename it to photo.jpg.
coscmd -b examplebucket1-1250000000 -r ap-guangzhou copy examplebucket2-1250000000.cos.ap-beijing.myqcloud.com/doc/picture.jpg doc/examplefolder/photo.jpg -H "{'x-cos-storage-class':'Archive'}"

Copy a folder

Command format.
coscmd copy -r <sourcepath> <cospath>
Operation example: Copy the examplefolder directory from the examplebucket2-1250000000 bucket to the doc directory in the examplebucket1-1250000000 bucket.
coscmd -b examplebucket1-1250000000 -r ap-guangzhou copy -r examplebucket2-1250000000.cos.ap-guangzhou.myqcloud.com/examplefolder doc/
Note:
Replace the parameters enclosed in "<>" with the source path (sourcepath) of the file to copy from COS and the destination path (cospath) of the file to copy to COS.
The format of sourcepath is: <BucketName-APPID>.cos.<region>.myqcloud.com/<cospath>.
Use the -d parameter to set x-cos-metadata-directive parameter, optional values are Copy and Replaced, the default is Copy.
When using the -H parameter to set the HTTP header, please make sure the format is JSON. Example: coscmd copy -H -d Replaced "{'x-cos-storage-class':'Archive','Content-Language':'zh-CN'}"<localpath><cospath>. For more headers, see PUT Object - Copy document.

Moving a file or folder

Attention:
The <sourcepath> and <cospath> for the move command cannot be the same, otherwise the file will be deleted. This is because the move command first copies and then deletes, so the file at the <sourcepath> path will ultimately be deleted.

Moving a file

Command format.
coscmd move <sourcepath> <cospath>
Operation example: Move the picture.jpg file from the examplebucket-1250000000 bucket to the doc folder within the same bucket.
coscmd -b examplebucket-1250000000 -r ap-chengdu move examplebucket-1250000000.cos.ap-chengdu.myqcloud.com/picture.jpg doc/
Operation example: Move the picture.jpg object from the examplebucket2-1250000000 bucket to the doc/folder/ directory in the examplebucket1-1250000000 bucket.
coscmd -b examplebucket1-1250000000 -r ap-guangzhou move examplebucket2-1250000000.cos.ap-beijing.myqcloud.com/picture.jpg doc/folder/
Operation example: Change the storage type of the object that has been moved to the destination bucket to STANDARD_IA.
coscmd -b examplebucket1-1250000000 -r ap-guangzhou move examplebucket2-1250000000.cos.ap-beijing.myqcloud.com/picture.jpg doc/folder/ -H "{'x-cos-storage-class':'STANDARD_IA'}"
Operation example: Change the storage type of the object that has been moved to the destination bucket to ARCHIVE.
coscmd -b examplebucket1-1250000000 -r ap-guangzhou move examplebucket2-1250000000.cos.ap-beijing.myqcloud.com/data/exampleobject data/examplefolder/exampleobject -H "{'x-cos-storage-class':'Archive'}"

Moving a folder

Command format.
coscmd move -r <sourcepath> <cospath>
Operation example: Move the examplefolder directory from the examplebucket2-1250000000 bucket to the doc directory in the examplebucket1-1250000000 bucket.
coscmd -b examplebucket1-1250000000 -r ap-guangzhou move -r examplebucket2-1250000000.cos.ap-guangzhou.myqcloud.com/examplefolder doc/
Note:
Replace the parameters enclosed in "<>" with the source path (sourcepath) of the file to move from COS and the destination path (cospath) of the file to move to COS.
The format of sourcepath is: <BucketName-APPID>.cos.<region>.myqcloud.com/<cospath>.
Use the -d parameter to set x-cos-metadata-directive parameter, optional values are Copy and Replaced, the default is Copy.
When using the -H parameter to set the HTTP header, ensure the format is JSON. Example: coscmd move -H -d Replaced "{'x-cos-storage-class':'Archive','Content-Language':'zh-CN'}" <sourcepath> <cospath>. For more headers, see the PUT Object - copy document.

Setting object access permissions

Command format.
coscmd putobjectacl --grant-<permissions> <UIN> <cospath>
Note:
Object access permissions can be set to --grant-read (which grants users read permission) and --grant-full-control (which grants users full control permission). For folders, they can also be set to --grant-write (which grants users write permission).
Operation example: Grant account 100000000001 read permission for picture.jpg.
coscmd putobjectacl --grant-read 100000000001 picture.jpg
Operation example: Query the access permissions of a file.
coscmd getobjectacl picture.jpg

Start/pause version control

Command format.
coscmd putbucketversioning <status>
Operation example: Enable versioning.
coscmd putbucketversioning Enabled
Operation example: Pause versioning.
coscmd putbucketversioning Suspended
Operation example: Query versioning.
coscmd getbucketversioning
Attention:
Replace the parameters in "<>" with the version control status you need.
Once you enable versioning on a bucket, it cannot be returned to a non-versioning status (initial status). However, you can pause versioning for the bucket so that subsequent uploads of objects will not result in multiple versions.

Restoring an archived file

Command format for restoring archived files.
coscmd restore <cospath>
Operation example: Restore picture.jpg in expedited retrieval mode with a validity period of 3 days.
coscmd restore -d 3 -t Expedited picture.jpg
Command format for batch restoring archived files.
coscmd restore -r <cospath>
Operation example: Restore the examplefolder/ directory in expedited retrieval mode with a validity period of 3 days.
coscmd restore -r -d 3 -t Expedited examplefolder/
Note:
Replace the parameters enclosed in "<>" with the COS path (cospath) of the file for which you need to query the file list.
Use -d <day> to set the expiration time for temporary copies. Default value: 7.
Use -t <tier> to specify the retrieval mode. Enumerated values: Expedited (expedited retrieval mode), Standard (standard retrieval mode), Bulk (batch retrieval mode). Default value: Standard.

FAQs

If you have any questions when using the COSCMD tool, see Frequently Asked Questions about COSCMD Utility Class.

Conclusions

COS not only provides the aforementioned applications and services but also offers multiple popular open-source applications and integrates Tencent Cloud COS plugins. Click here to launch and start using them immediately!

Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan