ossutil provides three types of commands: high-level commands, API-level commands, and helper commands.
Command structures
ossutil uses the following command structures, depending on the command type:
ossutil command [argument] [flags]
ossutil command subcommond [argument] [flags]
ossutil topic
argument: arguments. Arguments are of the string type.
flags: options. You can specify an option in the short form of
-o[=value] or -o [ value]
, or in the full form of--options[=value] or --options[ value]
. If you specify an exclusive option multiple times, only the last value takes effect.
Examples:
High-level command:
ossutil cat oss://bucket/object
Multi-level command:
ossutil api get-bucket-cors --bucket bucketexample
Helper command:
ossutil filter
Commands
ossutil provides three types of commands:
High-level commands
High-level commands perform common bucket and object tasks, such as creating buckets, deleting buckets, copying data, and modifying object attributes.
Command
Description
Creates a bucket.
Deletes a bucket.
Queries the storage size of the specified bucket or directory (prefix).
Displays the description of a bucket or object.
Creates an object whose name ends with a forward slash character (
/
).Appends content to 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.
Computes the hash of a file or object.
API-level commands
API-level commands provide direct access to Object Storage Service (OSS) API operations. You can specify parameters of an OSS API operation in the corresponding ossutil command.
The following table describes some of API-level commands. To get a full list of API-level commands, run the ossutil api -h
command.
Command | Description |
Sets or modifies the access control list (ACL) of a bucket. | |
Queries the ACL of a bucket. | |
.... | |
Creates cross-origin resource sharing (CORS) rules. | |
Queries CORS rules. | |
Deletes CORS rules. |
Helper commands
Helper commands provide auxiliary support, such as managing configurations and showing help information.
Command | Description |
Shows help information. | |
Creates a configuration file that stores configuration items, such as access credentials. | |
Updates ossutil to the latest version. | |
Shows the version of ossutil. | |
Performs a probe task. |
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 |
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).
--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. Example: 1.5d --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.
The following sample command creates a CORS rule by loading the CORS configuration from the cors-configuration.json file:
{
"CORSRule": {
"AllowedOrigin": ["www.aliyun.com"],
"AllowedMethod": ["PUT","GET"],
"MaxAgeSeconds": 10000
}
}
ossutil api put-bucket-cors --bucket examplebucket --cors-configuration file://cors-configuration.json
The 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}}
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 | ossutil api put-bucket-cors --bucket examplebucket --cors-configuration -
Command output control
Output formatting
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.
Value | 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:
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:
ossutil api get-bucket-cors --bucket bucketexample --output-format json
{
"CORSRule": {
"AllowedMethod": [
"PUT",
"GET"
],
"AllowedOrigin": "www.aliyun.com",
"MaxAgeSeconds": "10000"
},
"ResponseVary": "false"
}
Output query
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:
ossutil api get-bucket-cors --bucket bucketexample --output-query CORSRule.AllowedMethod --output-format json
[
"PUT",
"GET"
]
Friendly output 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.
Example of raw output display
ossutil stat oss://bucketexample
ACL : private
AccessMonitor : Disabled
ArchiveObjectCount : 2
ArchiveRealStorage : 10
ArchiveStorage : 131072
...
StandardObjectCount : 119212
StandardStorage : 66756852803
Storage : 66756852813
StorageClass : Standard
TransferAcceleration : Disabled
Example of friendly output display
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 : Disabled
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 Ctrl+C. |