ossutil is a command-line tool that allows you to efficiently manage Object Storage Service (OSS) resources from Windows, macOS, and Linux. This topic describes how to perform common bucket and object management operations by using commands, including creating and deleting buckets, and uploading, downloading, listing, and deleting objects.
In this topic, ossutil V2.0 is used. Compared with ossutil V1.0, ossutil V2.0 provides more advanced capabilities. We recommend that you use ossutil V2.0. ossutil V1.0 is also available. For information about how to use ossutil V1.0, see ossutil V1.0.
If you have installed and configured ossutil V2.0, you can quickly get started by referring to ossutil commands.
Prerequisites
An Alibaba Cloud Account is created.
OSS is activated.
Install ossutil
Linux
Install the unzip tool.
Alibaba Cloud Linux
sudo yum install -y unzip
CentOS
sudo yum install -y unzip
Ubuntu
sudo apt install -y unzip
Download the ossutil package.
curl -o ossutil-2.1.0-linux-amd64.zip https://gosspublic.alicdn.com/ossutil/v2/2.1.0/ossutil-2.1.0-linux-amd64.zip
NoteIn this example, ossutil for 64-bit x86 Linux is downloaded. To download ossutil for another system, see Download ossutil.
Enter the directory in which the ossutil package is stored and run the following unzip command:
unzip ossutil-2.1.0-linux-amd64.zip
Enter the ossutil-2.1.0-linux-amd64 directory.
cd ossutil-2.1.0-linux-amd64
Run the following command in the current directory:
chmod 755 ossutil
Run the following command to make ossutil globally invocable:
sudo mv ossutil /usr/local/bin/ && sudo ln -s /usr/local/bin/ossutil /usr/bin/ossutil
Run the
ossutil
command to check whether ossutil is installed:ossutil
If ossutil help information is returned, ossutil has been installed.
Windows
Install ossutil.
Download the ossutil package for your system architecture and bit version:
Extract the file from the ossutil package to a directory and enter the directory.
Configure an environment variable for the path of the file.
Click the address bar to copy the path of the current folder.
In the System variables section of the Environment Variables dialog box, locate and double-click the Path variable, click the New button, and paste the path of the file into the text box.
Run the
ossutil
command to check whether ossutil is installed:ossutil
If ossutil help information is returned, ossutil has been installed.
macOS
Install ossutil.
curl -o ossutil-2.1.0-mac-arm64.zip https://gosspublic.alicdn.com/ossutil/v2/2.1.0/ossutil-2.1.0-mac-arm64.zip
NoteIn this example, ossutil for 64-bit macOS ARM is downloaded. To download ossutil for another system, see Download ossutil.
Enter the directory in which the ossutil package is stored and run the following unzip command:
unzip ossutil-2.1.0-mac-arm64.zip
Enter the ossutil-2.1.0-mac-arm64 directory.
cd ossutil-2.1.0-mac-arm64
Run the following command in the current directory:
chmod 755 ossutil
Run the following command to make ossutil globally invocable:
sudo mv ossutil /usr/local/bin/ && sudo ln -s /usr/local/bin/ossutil /usr/bin/ossutil
Run the
ossutil
command to check whether ossutil is installed:ossutil
If ossutil help information is returned, ossutil has been installed.
Configure ossutil
Configure ossutil.
ossutil config
Configure the path of the configuration file. You can press the Enter key to use the default path of the configuration file.
This example shows how to configure ossutil on Linux.
Please enter the config file name,the file name can include path(default /root/.ossutilconfig, carriage return will use the default file. If you specified this option to other file, you should specify --config-file option to the file when you use other commands):
Enter the AccessKey ID that you created earlier.
Please enter Access Key ID [****************id]:LTAI****************
Enter the AccessKey secret that you created earlier.
Please enter Access Key Secret [****************sk]:R6vg*********************
Enter the ID of the region in which your data is stored on OSS.
Please enter Region [cn-hangzhou]:cn-hangzhou
In this example, the ID of the China (Hangzhou) region is used. For information about the IDs of other regions, see Regions and endpoints.
Specify an endpoint for the region. You can press Enter to skip this step. After you specify the region ID in the previous step, the public endpoint for the region is used by default. For example, if you set
region-id
tocn-hangzhou
, the public endpointhttps://oss-cn-hangzhou.aliyuncs.com
endpoint is used by default. If you want to use a different endpoint, enter the endpoint.Please enter Endpoint (optional, use public endpoint by default) [None]: https://oss-cn-hangzhou.aliyuncs.com
Sample commands
Create a bucket.
ossutil mb oss://examplebucket
If the output is similar to the following content, the bucket has been created.
0.668238(s) elapsed
Upload an object to the bucket.
Create a local file named
uploadFile.txt
.echo 'Hello, OSS!' > uploadFile.txt
Upload the file to the
examplebucket
.ossutil cp uploadFile.txt oss://examplebucket
If the output is similar to the following content, the file has been uploaded to the bucket.
Success: Total 1 file, size 12 B, Upload done:(1 objects, 12 B), avg 44 B/s 0.271779(s) elapsed
Download the object.
Download the uploadFile.txt object from the bucket to a directory named localfolder.
ossutil cp oss://examplebucket/uploadFile.txt localfolder/
If the output is similar to the following content, the object has been downloaded to the local directory.
Success: Total 1 object, size 12 B, Download done:(1 files, 12 B), avg 74 B/s 0.162447(s) elapsed
List objects in the bucket.
ossutil ls oss://examplebucket
If the output is similar to the following content, objects in the bucket have been listed.
LastModifiedTime Size(B) StorageClass ETAG ObjectName 2024-11-26 14:35:29 +0800 CST 12 Standard 1103F650EB2C292D179A032D2A97B0F5 oss://examplebucket/uploadFile.txt Object Number is: 1 0.124679(s) elapsed
Delete the uploadFile.txt object from the bucket.
ossutil rm oss://examplebucket/uploadFile.txt
If the output is similar to the following content, the object has been deleted from the bucket.
0.295530(s) elapsed
Delete the bucket.
ossutil rb oss://examplebucket
If the output is similar to the following content, the bucket has been deleted.
0.478659(s) elapsed