Alibaba Cloud CLI integrates ossutil, the command-line interface (CLI) for Object Storage Service (OSS). This integration lets you manage OSS resources in a unified CLI environment. This topic describes how to use ossutil with Alibaba Cloud CLI.
Background
ossutillets you manage OSS data from Windows, Linux, or macOS systems. It is integrated as a plugin into Alibaba Cloud CLI. You can callossutildirectly from Alibaba Cloud CLI to manage core OSS resources, such as buckets and objects.Starting from
version 3.0.304, Alibaba Cloud CLI integratesossutil 2.0to provide a more stable and efficient user experience. It is compatible with bothossutil 1.0andossutil 2.0, and the commands of ossutil 1.0 can still be used. We recommend that you upgrade Alibaba Cloud CLI to the latest version to take advantage of all the new features and performance improvements ofossutil 2.0.The main differences between
ossutil 1.0andossutil 2.0in Alibaba Cloud CLI are as follows:
ossutil 2.0
In the latest version of Alibaba Cloud CLI, ossutil 2.0 supports automatic checks and upgrades to the latest version. You do not need to run the
updatecommand.The ossutil 2.0 version is independent of the Alibaba Cloud CLI version. Updates are not dependent on the CLI version.
Syntax
The command syntax for ossutil 2.0 in Alibaba Cloud CLI is as follows:
aliyun ossutil command [argument] [flags]
aliyun ossutil command subcommond [argument] [flags]
aliyun ossutil topicargument: the parameter, which is a string.flags: the option. Supports the short name style-o[=value]/ -o [value]and the long name style--options[=value]/--options[value]. If you specify an exclusive option multiple times, only the last value takes effect.
The following are command examples:
Command:
aliyun ossutil cat oss://bucket/objectMulti-level command:
aliyun ossutil api get-bucket-cors --bucket bucketexampleHelper command:
aliyun ossutil filter
Commands
ossutil 2.0 provides three types of commands: high-level commands, API-level commands, and auxiliary commands.
High-level commands: Used for common operations on objects or buckets, such as creating and deleting buckets, copying data, and modifying object attributes.
Command
Description
Creates a bucket.
Deletes a bucket.
Queries the size of a bucket or directory (prefix).
Displays the description of a bucket or an object.
Creates an object whose name ends with the
/character.Appends content to the end of an appendable object.
Sends object content to the standard output.
Lists buckets or objects.
Uploads, downloads, or copies an object.
Deletes an object.
Sets object attributes.
Generates a signed URL for an object.
Restores a frozen object.
Reverts an object to the specified version.
Synchronizes directories or objects from the source to the destination.
Calculates the hashof a file or an object.
API-level commands: Provide direct access to API operations and support the configuration parameters of the corresponding API operations.
Command
Description
Sets or modifies the ACL of a bucket.
Queries the ACL of a bucket.
....
Creates cross-origin resource sharing (CORS) rules.
Queries CORS rules.
Deletes CORS rules.
...
Auxiliary commands: Used for tasks such as configuring files and accessing additional help information.
Command
Description
Gets help information.
Creates a configuration file to store configuration items and access credentials.
Shows the version of ossutil.
Performs a probe task.
Command-line options
Command-line options in ossutil 2.0 are divided into global and local options. Global options apply to all commands. Local options apply only to specific commands. Command-line options have the highest priority and can override parameters set in configuration files or environment variables.
Query command-line options
Use command-line options
Global command-line options
Option types
Type | Option | Description |
String | --option string |
Example: --acl private |
Boolean | --option | Turn on or off an option. Example: --dry-run |
Integer | --option Int | The option takes an unsigned integer as its value. Example: --read-timeout 10 |
The timestamp. | --option Time | A timestamp (DateTime or Date) in the ISO 8601 format. Example: --max-mtime 2006-01-02T15:04:05 |
Size suffix | --option SizeSuffix | The size unit. The default unit is B. Other units include K (KiB), M (MiB), G (GiB), T (TiB), P (PiB), and E (EiB). For example, a minimum size of 1024 bytes can be specified as: --min-size 1024 --min-size 1K |
Time unit | --option Duration | The time unit. The default unit is seconds (s). Supported time units are milliseconds (ms), seconds (s), minutes (m), hours (h), days (d), weeks (w), months (M), and years (y). The numerical value can be a decimal. For example, a minimum time unit of 1.5 days can be specified as: --min-age 1.5d |
String list | --option strings | You can specify an option once or multiple times in a command. You can specify a single value or multiple comma-separated values for each occurrence of the option. Example: --metadata user=jack,email=ja**@test.com --metadata address=china |
String array | --option stringArray | You can specify an option once or multiple times in a command. You can specify only one value for each occurrence of the option. Example: --include *.jpg --include *.txt |
Load data from files
In most cases, you specify parameter values directly in command lines. When you need to process complex values, loading values from a file provides more efficiency. When you chain commands, you must specify parameter values by using the standard input. When a parameter can take values by using different methods:
If the value starts with
file://, data is loaded from the specified file.If the value is
-, data is loaded from the standard input.
For example, you want to create a CORS rule, which is configured in the JSON format. The following sample command creates the CORS rule by loading the CORS configuration from the cors-configuration.json file:
{
"CORSRule": {
"AllowedOrigin": ["www.aliyun.com"],
"AllowedMethod": ["PUT","GET"],
"MaxAgeSeconds": 10000
}
}aliyun ossutil api put-bucket-cors --bucket examplebucket --cors-configuration file://cors-configuration.jsonThe following sample command creates a CORS rule by taking JSON configuration data in the command line:
{"CORSRule":{"AllowedOrigin":["www.aliyun.com"],"AllowedMethod":["PUT","GET"],"MaxAgeSeconds":10000}}aliyun ossutil api put-bucket-cors --bucket examplebucket --cors-configuration "{\"CORSRule\":{\"AllowedOrigin\":[\"www.aliyun.com\"],\"AllowedMethod\":[\"PUT\",\"GET\"],\"MaxAgeSeconds\":10000}}"The following sample command creates a CORS rule by taking the configuration from the standard input:
cat cors-configuration.json | aliyun ossutil api put-bucket-cors --bucket examplebucket --cors-configuration -Control command output
Output format
You can use the --output-format parameter in the du, stat, and ls commands and the subcommands of the api command to format the output. The following table describes the valid values of the --output-format option.
Format | Description |
raw | Returns output in the raw format, that is, the format in which the server returns the content. |
json | Returns the output in the JSON format. |
yaml | Returns the output in the YAML format. |
In the following example, the output of the get-bucket-cors command is in the raw format:
aliyun ossutil api get-bucket-cors --bucket bucketexample
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration>
<CORSRule>
<AllowedOrigin>www.aliyun.com</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>10000</MaxAgeSeconds>
</CORSRule>
<ResponseVary>false</ResponseVary>
</CORSConfiguration>In the following example, the output is formatted in JSON:
aliyun ossutil api get-bucket-cors --bucket bucketexample --output-format json
{
"CORSRule": {
"AllowedMethod": [
"PUT",
"GET"
],
"AllowedOrigin": "www.aliyun.com",
"MaxAgeSeconds": "10000"
},
"ResponseVary": "false"
}Filter output
ossutil provides a built-in JSON-based output query mechanism. You can use the --output-query value option to query output.
The option applies only to subcommands in the API command set.
The output query feature is based on JMESPath. When you use the output query feature, the output is formatted in JSON, filtered based on JMESPath query expressions, and returned in the specified format. For more information about JMEPath, see JMESPath Specification.
In the following example, the get-bucket-cors command returns only the value of the AllowedMethod parameter:
aliyun ossutil api get-bucket-cors --bucket bucketexample --output-query CORSRule.AllowedMethod --output-format json
[
"PUT",
"GET"
]Human-readable display
ossutil provides the --human-readable option that allows the data sizes and quantities in the output of the du and stat commands to be displayed in a more human-readable way. Specifically, data sizes are displayed in 1024-based KiB, MiB, GiB, TiB, and PiB, and quantities are displayed by using the 1000-based unit abbreviations k, m, g, t, and p.
Raw mode example
aliyun ossutil stat oss://bucketexample
ACL : private
AccessMonitor : Disabled
ArchiveObjectCount : 2
ArchiveRealStorage : 10
ArchiveStorage : 131072
...
StandardObjectCount : 119212
StandardStorage : 66756852803
Storage : 66756852813
StorageClass : Standard
TransferAcceleration : DisabledHuman-readable mode example
aliyun ossutil stat oss://bucketexample --human-readable
ACL : private
AccessMonitor : Disabled
ArchiveObjectCount : 2
ArchiveRealStorage : 10
ArchiveStorage : 131.072k
...
StandardObjectCount : 119.212k
StandardStorage : 66.757G
Storage : 66.757G
StorageClass : Standard
TransferAcceleration : DisabledCommand return codes
When a call to ossutil is made by using a process, the echo information cannot be displayed in real time. When a process run finishes, a return code is displayed based on the result. You can run the following commands to display the return code for the previously executed command and use the return code for troubleshooting.
Linux
Run the echo $? command to display the return code of the previously executed command.
Windows
Run the echo %errorlevel% command to display the return code of the previously executed command.
macOS
Run the echo $? command to display the return code of the previously executed command.
Return code | Description |
0 | Indicates success. The request sent to the server was handled successfully and the server returned status code 200. |
1 | Indicates a parameter error. For example, the required subcommand or parameter is missing, or the command or parameter is unknown. |
2 | Indicates a server error. The command successfully sent the request to the server, but the server returned an error (a status code other than 2xx). |
3 | Indicates a non-server-side error during calls to OSS SDK for Go. |
4 | Indicates a partial failure in batch processing, for example, by using the cp or rm command. |
5 | Indicates an interruption. The command was canceled by using |
Examples
Example 1: Upload the local file upload.rar to a bucket named bucket at a speed of 20 MB/s. The default unit is bytes per second (B/s).
aliyun ossutil cp D:\\upload.rar oss://bucket/ --bandwidth-limit 20971520Example 2: Upload the local file file.rar to a bucket named bucket at a speed of 50 MB/s. The specified unit is megabytes per second (MB/s).
aliyun ossutil cp D:\\file.rar oss://bucket/dir -r --bandwidth-limit 50MExample 3: Download the object download.rar from a bucket named bucket to the current directory and limit the download speed to 20 MB/s.
aliyun ossutil cp oss://bucket/download.rar . --bandwidth-limit 20971520
ossutil 1.0
FAQ
If you encounter an error when you use ossutil, see the following topics to troubleshoot the error.