ossutil is a command-line tool for managing Alibaba Cloud Object Storage Service (OSS) on Windows, macOS, and Linux systems. It allows you to perform batch operations and automate tasks efficiently. This guide covers operations such as creating buckets, uploading and downloading files, listing files, and deleting files and buckets using the command line.
-
This guide uses ossutil 2.0 as an example. ossutil 2.0 offers a comprehensive upgrade in features compared to ossutil 1.0. We strongly recommend using the latest version of ossutil 2.0. For information on ossutil 1.0, please refer to ossutil 1.0.
-
If you have already installed and configured ossutil 2.0, you can refer directly to ossutil 2.0 commands.
Prerequisites
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.0.6-beta.01091200-linux-amd64.zip https://gosspublic.alicdn.com/ossutil/v2-beta/2.0.6-beta.01091200/ossutil-2.0.6-beta.01091200-linux-amd64.zip
NoteThis example downloads ossutil for a 64-bit Linux x86 system. For other systems, see Download ossutil.
-
Extract the package in the directory where it was downloaded.
unzip ossutil-2.0.6-beta.01091200-linux-amd64.zip
-
Navigate to the ossutil-2.0.6-beta.01091200-linux-amd64 directory.
cd ossutil-2.0.6-beta.01091200-linux-amd64
-
Run the following command in the current directory.
chmod 755 ossutil
-
Enable global invocation of ossutil with the following command.
sudo mv ossutil /usr/local/bin/ && sudo ln -s /usr/local/bin/ossutil /usr/bin/ossutil
-
Verify the installation of ossutil by running the
ossutil
command.ossutil
If ossutil's help information is displayed, the installation was successful.
Windows
-
Install ossutil.
-
Download the installation package for your system:
-
x86_32 architecture: Windows x86 32bit.
-
x86_64 architecture: Windows x86 64bit.
-
For Windows 7, Windows 8, or Windows Server 2008R2: Windows 7, Windows 8, Windows Server 2008R2.
-
-
Extract the .zip package to the target folder and navigate to the extracted directory as shown in the figure.
-
Copy the path of the extracted ossutil folder to configure the system environment variable.
-
Click the path bar of the current directory and copy the displayed path.
-
Open the Environment Variables dialog box. In the System Variables section, find and double-click the Path variable. Click the New button, and then paste the copied path of the ossutil folder into the new entry box.
-
-
Verify the installation of ossutil by running the
ossutil
command.ossutil
If ossutil's help information is displayed, the installation was successful.
-
macOS
-
Install ossutil.
curl -o ossutil-2.0.6-beta.01091200-mac-arm64.zip https://gosspublic.alicdn.com/ossutil/v2-beta/2.0.6-beta.01091200/ossutil-2.0.6-beta.01091200-mac-arm64.zip
NoteThis example downloads ossutil for a 64-bit macOS ARM system. For other systems, see Download ossutil.
-
Extract the package in the directory where it was downloaded.
unzip ossutil-2.0.6-beta.01091200-mac-arm64.zip
-
Navigate to the ossutil-2.0.6-beta.01091200-mac-arm64 directory.
cd ossutil-2.0.6-beta.01091200-mac-arm64
-
Run the following command in the current directory.
chmod 755 ossutil
-
Enable global invocation of ossutil with the following command.
sudo mv ossutil /usr/local/bin/ && sudo ln -s /usr/local/bin/ossutil /usr/bin/ossutil
-
Verify the installation of ossutil by running the
ossutil
command.ossutil
If ossutil's help information is displayed, the installation was successful.
Configure ossutil
-
Configure ossutil.
ossutil config
-
Set the path of the ossutil configuration file as prompted. Press Enter to use the default path.
The following prompt is based on a Linux system.
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 you created earlier when prompted.
Please enter Access Key ID [****************id]:LTAI****************
-
Enter the AccessKey Secret you created earlier when prompted.
Please enter Access Key Secret [****************sk]:R6vg*********************
-
Enter the region ID of the OSS data center when prompted.
Please enter Region [cn-hangzhou]:cn-hangzhou
This guide uses Hangzhou as an example. For other regions' IDs, see OSS regions and endpoints.
-
If you do not need to customize the endpoint, press Enter to skip this step. By default, the public endpoint corresponding to the region ID is used. For instance, if the
region-id
is set tocn-hangzhou
, the default public endpoint ishttps://oss-cn-hangzhou.aliyuncs.com
. To customize the endpoint, enter your specific endpoint information.Please enter Endpoint (optional, use public endpoint by default) [None]: https://oss-cn-hangzhou.aliyuncs.com
Example
-
Create a bucket.
ossutil mb oss://examplebucket
If the output is similar to the following, the bucket named examplebucket has been created.
0.668238(s) elapsed
-
Upload a file to the bucket.
-
Create a local file named
uploadFile.txt
.echo 'Hello, OSS!' > uploadFile.txt
-
Upload the file to the bucket named
examplebucket
.ossutil cp uploadFile.txt oss://examplebucket
If the output is similar to the following, the file has been uploaded to
examplebucket
.Success: Total 1 file, size 12 B, Upload done:(1 objects, 12 B), avg 44 B/s 0.271779(s) elapsed
-
-
Download a file.
Download the sample file uploadFile.txt from examplebucket to the local folder named localfolder.
ossutil cp oss://examplebucket/uploadFile.txt localfolder/
If the output is similar to the following, the file has been downloaded to the local folder named localfolder.
Success: Total 1 object, size 12 B, Download done:(1 files, 12 B), avg 74 B/s 0.162447(s) elapsed
-
List files in examplebucket.
ossutil ls oss://examplebucket
If the output is similar to the following, the files in examplebucket are 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 uploadFile.txt from examplebucket.
ossutil rm oss://examplebucket/uploadFile.txt
If the output is similar to the following, uploadFile.txt has been deleted from examplebucket.
0.295530(s) elapsed
-
Delete examplebucket.
ossutil rb oss://examplebucket
If the output is similar to the following, examplebucket has been deleted.
0.478659(s) elapsed
References
For more information about common issues during the use of ossutil, see ossutil 2.0 FAQ.