pip
command to install COSCMD:pip install coscmd
-v
or --version
command to view the version information.C:\\python_install_dir
and C:\\python_install_dir\\Scripts
paths to environment variables. pip install coscmd -U
git clone https://github.com/tencentyun/coscmd.gitcd coscmdpython setup.py install
# Run the following commands on a device that is connected to the Internetmkdir coscmd-packagespip download coscmd -d coscmd-packagestar -czvf coscmd-packages.tar.gz coscmd-packages# Copy the installation package to a device that is not connected to the Internet and run the following commandstar -xzvf coscmd-packages.tar.gzpip install coscmd --no-index -f coscmd-packages
-h
or --help
command to view the information and usage of COSCMD.coscmd -h
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 moreinformations. 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 firstupload Upload file or directory to COSdownload Download file from COS to localdelete Delete file or files on COSabort Aborts upload parts on COScopy Copy file from COS to COSmove move file from COS to COSlist List files on COSlistparts List upload partsinfo Get the information of file on COSrestore Restoresignurl Get download urlcreatebucket Create bucketdeletebucket Delete bucketputobjectacl Set object aclgetobjectacl Get object aclputbucketacl Set bucket aclgetbucketacl Get bucket aclputbucketversioningSet the versioning stategetbucketversioningGet the versioning stateprobe Connection testoptional arguments:-h, --help show this help message and exit-d, --debug Debug mode-s, --silence Silence mode-b BUCKET, --bucket BUCKETSpecify bucket-r REGION, --region REGIONSpecify region-c CONFIG_PATH, --config_path CONFIG_PATHSpecify config_path-l LOG_PATH, --log_path LOG_PATHSpecify log_path--log_size LOG_SIZE specify max log size in MB (default 1MB)--log_backup_count LOG_BACKUP_COUNTspecify log backup num-v, --version show program's version number and exit
-h
after each command (with no parameter appended) to see how to use the command. For example:coscmd upload -h // View how to use the upload command
~/.cos.conf
.configure-bucket-1250000000
) for parameter configuration and create a key.[common]secret_id = AKIDA6wUmImTMzvXZNbGLCgtusZ2E8mG****secret_key = TghWBCyf5LIyTcXCoBdw1oRpytWk****bucket = configure-bucket-1250000000region = ap-chengdumax_thread = 5part_size = 1retry = 5timeout = 60schema = httpsverify = md5anonymous = False
timeout
item in the configuration file, in seconds, indicates the timeout period for reading and writing data.schema
can be set to http
or https
(default).anonymous
can be set to True
or False
. If it is set to True
, the anonymous mode is used (the signature is empty).coscmd config -h
command.config
commandconfig
command to automatically generate a configuration file in ~/.cos.conf
. The 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]
Option | Parameter Description | Valid Value | Required |
-a | Key ID, which can be obtained at Manage API Key | String | Yes |
-s | Key, which can be obtained at Manage API Key | String | Yes |
-t | Temporary key token, which needs to be specified in the x-cos-security-token header when a temporary key is used. | String | No |
-b | Name of the specified bucket, formatted as BucketName-APPID . For more information, see Naming Conventions. If this is your first time using COSCMD, you need to create a bucket in the COS console to configure COSCMD. | String | Yes |
-r | String | Yes | |
-e | Endpoint of the request. Once you configure this parameter, the region parameter will be invalidated. If you use the default endpoint, this parameter is formatted as cos.<region>.myqcloud.com ; if you use a global acceleration endpoint, the format is cos.accelerate.myqcloud.com . | String | No |
-m | Maximum number of threads for multithreaded operation (default is 5). If the file upload is slow, you can increase this value. The number of threads depends on the machine's performance. Assuming the machine supports a maximum of 30 threads, you can adjust the concurrent threads to 30 to fully utilize the machine performance. The command is coscmd config -m 30 . | Number | No |
-p | Size of the multipart upload part, in MB (default: 1; value range: 1-1000) | Number | No |
--do-not-use-ssl | Uses the HTTP protocol instead of HTTPS | String | No |
--anonymous | Anonymous operation (without carrying a signature) | String | No |
config
command:coscmd config -a AChT4ThiXAbpBDEFGhT4ThiXAbp**** -s WE54wreefvds3462refgwewe**** -b configure-bucket-1250000000 -r ap-chengdu
-b <BucketName-APPID>
parameter to specify the bucket name, which must be formatted as BucketName-APPID
.-r <region>
parameter to specify the region where the bucket resides.coscmd -b <BucketName-APPID> -r <region> <action> ...
examplebucket
that resides in the Beijing regioncoscmd -b examplebucket-1250000000 -r ap-beijing createbucket
examplebucket
bucketcoscmd -b examplebucket-1250000000 -r ap-beijing upload D:/picture.jpg /
~/.cos.conf
will be used by default. Similarly, if you do not specify the log file path, ~/.cos.log
will be used by default.-c <conf_path>
parameter to specify the configuration file path. COSCMD will read configuration information from the path when running.-l <log_conf>
parameter to specify the log file path. COSCMD will output the logs generated at runtime to the log files in the path.coscmd -c <conf_path> -l <log_conf> <action> ...
/data/home/cos_conf
and the log path to /data/home/cos_log
, and creating a bucket named examplebucket
in the Beijing region.coscmd -c /data/home/cos_conf -l /data/home/cos_log -b examplebucket-1250000000 -r ap-beijing createbucket
-d
or -debug
is added before a command, detailed operation information will be displayed when executing the command, as shown in the example below:coscmd -d upload <localpath> <cospath>
coscmd -d upload -rs D:/folder/ /
-s
or --silence
in each command so that no message will be output.coscmd -s upload <localpath> <cospath>
coscmd -s upload D:/picture.jpg /
-b <BucketName-APPID>
and -r <Region>
when you run the coscmd createbucket
command; otherwise, an error may be reported. This is because if the bucket and region are not specified, this command takes effect for the bucket that is used to configure COSCMD.coscmd -b <BucketName-APPID> createbucket
examplebucket
that resides in the Beijing regioncoscmd -b examplebucket-1250000000 -r ap-beijing createbucket
coscmd deletebucket
takes effect only for the bucket that is used to configure COSCMD. To delete another bucket, run the command with the -b <BucketName-APPID>
and -r <region>
parameters specified.coscmd -b <BucketName-APPID> deletebucket
coscmd -b examplebucket-1250000000 -r ap-beijing deletebucket
coscmd -b examplebucket-1250000000 -r ap-beijing deletebucket -f
-f
parameter will forcibly delete the bucket, including all files, noncurrent folders (if versioning is enabled), and incomplete multipart uploads.coscmd upload <localpath> <cospath>
coscmd upload D:/picture.jpg doc/
coscmd upload D:/doc/picture.jpg doc/
coscmd upload D:/picture.jpg doc/ -H "{'x-cos-storage-class':'Archive'}"
-H
parameter, please use the JSON format, for example, coscmd upload -H "{'x-cos-storage-class':'Archive','Content-Language':'zh-CN'}" <localpath> <cospath>
. For more information about the headers, see PUT Object.coscmd upload D:/picture.jpg doc/ -H "{'x-cos-meta-example':'example'}"
coscmd upload D:/doc/file.zip doc/ -H "{'x-cos-traffic-limit':'819200'}"
coscmd upload -r <localpath> <cospath>
upload
command in cmd or PowerShell that comes with the system. Other tools, such as Git Bash, have a different command path resolution strategy than PowerShell and can cause users' files to be uploaded to an incorrect path.coscmd upload -r D:/doc /
coscmd upload -r D:/doc doc
coscmd upload -rs D:/doc doc
-s
parameter to upload files synchronously while skipping those with the same MD5 value (please note that the source files in COS must have been uploaded using COSCMD v1.8.3.2 or above; the x-cos-meta-md5
header is included by default).coscmd upload -rs --skipmd5 D:/doc doc
-s
parameter allows synchronous upload, and the --skipmd5
parameter can be used to skip files with the same name and same file size.coscmd upload -rs --delete D:/doc /
coscmd upload -rs D:/doc / --ignore *.txt,*.doc
coscmd upload -rs D:/doc / --ignore "*.txt"
--ignore
parameter, or filter certain types of files by using --include
. Multiple shell wildcard rules (separated by commas ,
) are supported. To ignore a specified extension, ,
must be added at the end, or ""
must be used to enclose the extension. If ""
contains multiple comma-separated rules, the first rule prevails.--ignore
to filter all files in a particular folder, you need to use an absolute path and use ""
to enclose the path, for example, coscmd upload -rs D:/doc / --ignore "D:/doc/ignore_folder/*"
.coscmd upload -rs D:/doc / --include *.txt,*.doc
coscmd upload -rs D:/doc / --include "*.txt"
coscmd upload <localpath> <cospath>
(same as simple upload).x-cos-meta-md5
header is carried by default, whose value is the file's MD5 checksum. If the command has carried the --skipmd5
parameter, this header will not be carried.coscmd list <cospath>
coscmd list doc/
coscmd list -ar
coscmd list examplefolder/ -ar
coscmd list -v
<cospath>
is empty, the root directory of the current bucket is queried.-a
to query all files.-r
to query files recursively. The number and total size of the files are listed at the end of the returned result.-n num
to set the maximum number of files to query.coscmd info <cospath>
coscmd info doc/picture.jpg
coscmd download <cospath> <localpath>
coscmd download doc/picture.jpg D:/picture.jpg
coscmd download doc/picture.jpg D:/
coscmd download picture.jpg --versionId MTg0NDUxMzc2OTM4NTExNTg7Tjg D:/
coscmd download -r <cospath> <localpath>
coscmd download -r doc D:/folder/
doc
directory that is under the root directorycoscmd download -r / D:/ --ignore "doc/*"
coscmd download -rf / D:/examplefolder/
-f
parameter to overwrite the local file.coscmd download -rs / D:/examplefolder
-s
or --sync
parameter to skip identical files that already exist locally when downloading a folder (provided that the downloaded files were uploaded via the COSCMD upload
API and the x- cos-meta-md5
header was included).coscmd download -rs --skipmd5 / D:/examplefolder
coscmd download -rs --delete / D:/doc /
coscmd download -rs / D:/examplefolder --ignore *.txt,*.doc
coscmd download -rs / D:/examplefolder --ignore "*.txt"
--ignore
parameter, or filter certain types of files by using --include
. Multiple shell wildcard rules (separated by commas ,
) are supported. To ignore a specified extension, ,
must be added at the end, or ""
must be used to enclose the extension. If ""
contains multiple comma-separated rules, the first rule prevails.--ignore
to filter all files in a particular directory, you need to use an absolute path and use ""
to enclose the path, for example, coscmd upload -rs D:/doc / --ignore "D:/doc/ignore_folder/*"
.coscmd download -rs / D:/examplefolder --include *.txt,*.doc
coscmd download -rs / D:/examplefolder --include "*.txt"
mget
API is disused, please use the download
API for multipart downloads.coscmd signurl <cospath>
coscmd signurl doc/picture.jpg
coscmd signurl doc/picture.jpg -t 100
-t time
parameter sets the effective time (in seconds) of the URL signature. The default value is 10000.coscmd delete <cospath>
coscmd delete doc/exampleobject.txt
coscmd delete doc/exampleobject.txt --versionId MTg0NDUxMzc4ODA3NTgyMTErEWN
coscmd delete -r <cospath>
doc
foldercoscmd delete -r doc
folder/doc
foldercoscmd delete -r folder/doc
doc
directorycoscmd delete -r doc/ --versions
y
to confirm a batch delete operation. You can skip this step if the -f
parameter is used.coscmd listparts <cospath>
coscmd listparts doc/
coscmd abort
coscmd abort
coscmd copy <sourcepath> <cospath>
examplebucket-1250000000
bucket to the "doc" foldercoscmd -b examplebucket-1250000000 -r ap-chengdu copy examplebucket-1250000000.ap-chengdu.myqcloud.com/picture.jpg doc/
examplebucket2-1250000000
bucket to "doc/examplefolder/" in the examplebucket1-1250000000
bucket.coscmd -b examplebucket1-1250000000 -r ap-guangzhou copy examplebucket2-1250000000.ap-beijing.myqcloud.com/doc/picture.jpg doc/examplefolder/
coscmd -b examplebucket1-1250000000 -r ap-guangzhou copy examplebucket2-1250000000.ap-beijing.myqcloud.com/doc/picture.jpg doc/examplefolder/ -H "{'x-cos-storage-class':'STANDARD_IA'}"
coscmd -b examplebucket1-1250000000 -r ap-guangzhou copy examplebucket2-1250000000.ap-beijing.myqcloud.com/doc/picture.jpg doc/examplefolder/photo.jpg -H "{'x-cos-storage-class':'Archive'}"
coscmd copy -r <sourcepath> <cospath>
examplefolder
directory in the examplebucket2-1250000000
bucket to the doc
directory in the examplebucket1-1250000000
bucketcoscmd -b examplebucket1-1250000000 -r ap-guangzhou copy -r examplebucket2-1250000000.cos.ap-guangzhou.myqcloud.com/examplefolder doc/
<BucketName-APPID>.cos.<region>.myqcloud.com/<cospath>
.-d
parameter to set the x-cos-metadata-directive
header. Valid values are Copy
(default) and Replaced
.-H
parameter, use the JSON format, for example, coscmd copy -H -d Replaced "{'x-cos-storage-class':'Archive','Content-Language':'zh-CN'}" <localpath> <cospath>
. For more information about the headers, see PUT Object - Copy.move
command, <sourcepath>
and <cospath>
cannot be the same. Otherwise, files will be deleted. The reason is that the move
command copies files first and then deletes them, and the files in the <sourcepath>
path are eventually deleted.coscmd move <sourcepath> <cospath>
examplebucket-1250000000
bucket to the "doc" folder coscmd -b examplebucket-1250000000 -r ap-chengdu move examplebucket-1250000000.ap-chengdu.myqcloud.com/picture.jpg doc/
examplebucket2-1250000000
bucket to "doc/folder/" in the examplebucket1-1250000000
bucketcoscmd -b examplebucket1-1250000000 -r ap-guangzhou move examplebucket2-1250000000.ap-beijing.myqcloud.com/picture.jpg doc/folder/
coscmd -b examplebucket1-1250000000 -r ap-guangzhou move examplebucket2-1250000000.ap-beijing.myqcloud.com/picture.jpg doc/folder/ -H "{'x-cos-storage-class':'STANDARD_IA'}"
coscmd -b examplebucket1-1250000000 -r ap-guangzhou move examplebucket2-1250000000.ap-beijing.myqcloud.com/data/exampleobject data/examplefolder/exampleobject -H "{'x-cos-storage-class':'Archive'}"
coscmd move -r <sourcepath> <cospath>
examplebucket2-1250000000
bucket to the "doc" directory in the examplebucket1-1250000000
bucketcoscmd -b examplebucket1-1250000000 -r ap-guangzhou move -r examplebucket2-1250000000.cos.ap-guangzhou.myqcloud.com/examplefolder doc/
<BucketName-APPID>.cos.<region>.myqcloud.com/<cospath>
.-d
parameter to set the x-cos-metadata-directive
header. Valid values are Copy
(default) and Replaced
.-H
parameter, use the JSON format, for example, coscmd move -H -d Replaced "{'x-cos-storage-class':'Archive','Content-Language':'zh-CN'}" <localpath> <cospath>
. For more information about the headers, see PUT Object - Copy.coscmd putobjectacl --grant-<permissions> <UIN> <cospath>
100000000001
permission to read "picture.jpg"coscmd putobjectacl --grant-read 100000000001 picture.jpg
coscmd getobjectacl picture.jpg
coscmd putbucketversioning <status>
coscmd putbucketversioning Enabled
coscmd putbucketversioning Suspended
coscmd getbucketversioning
coscmd restore <cospath>
coscmd restore -d 3 -t Expedited picture.jpg
coscmd restore -r <cospath>
coscmd restore -r -d 3 -t Expedited examplefolder/
-d <day>
to set the validity period of the temporary copy. Default value: 7
.-t <tier>
to specify the restoration mode. Enumerated values: Expedited
(Expedited retrieval), Standard
(Standard retrieval), and Bulk
(bulk retrieval). Default value: Standard
.
Was this page helpful?