Cloud Open Source oracle

Working with Oracle Cloud Storage from the Command Line

In our previous post we talked about general aspects of Oracle Cloud Storage Buckets, and this time we will go through some basic commands to manage buckets, objects and versioning. Enjoy!


Oracle Cloud Infrastructure Cloud (OCI) Shell is a web browser-based terminal accessible from the Oracle Cloud Console. Cloud Shell is free to use (within monthly tenancy limits), and provides access to a Linux shell, with a pre-authenticated Oracle Cloud Infrastructure CLI, a pre-authenticated Ansible installation, and other useful tools for following Oracle Cloud Infrastructure service tutorials and labs. Cloud Shell is a feature available to all OCI users, accessible from the Console.

Cloud Shell provides:

  • An ephemeral machine to use as a host for a Linux shell, pre-configured with the latest version of the OCI Command Line Interface (CLI) and a number of useful tools
  • 5GB of storage for your home directory
  • A persistent frame of the Console which stays active as you navigate to different pages of the console

Create a bucket

1. Click the Cloud Shell icon in the upper-right corner of the Console:

In the default bash prompt in Cloud Shell, the region that the OCI CLI is interacting with is echoed in the Cloud Shell command line prompt:

2. Enter the following command to list the available commands and help topics in

oci os bucket -h

pressing spacebar to advance the output:

3. Create a bucket using the oci os bucket create command:

oci os bucket create --name bucket-test --compartment-id ocid1.tenancy.oc1..aaaaaaaaxe5a7xuzsrqawsih2kzxm2cricjz2gr7izr574pnukxp2haaqp4q

In this case we have created a Standard Bucket with Storage Tier Standard, with Private access. As we’ve seen in the help, you can customize the settings adding more parameters.

Uploading Files to Oracle Cloud Storage

The oci os bucket command is very versatile. You can upload files from local storage or objects from other Cloud Storage buckets.

Download a couple of sample image file to an images directory:

mkdir images
curl -o images/oraclecloud.png

Upload the file from images directory to your Cloud Storage bucket:

oci os object bulk-upload -ns axzt5tlh3ol3 -bn bucket-test --src-dir /home/aliciathom/images

Understanding Object Versioning

With Cloud Storage is possible of keeping track of any object version. This helps you to recover from unintended removal and alteration.
You can enable object versioning at bucket creation time or later. Versioning is disabled by default.
Each Object Storage bucket has object versioning status of disabled, enabled, or suspended

List the details of the bucket to observe the status of versioning

oci os bucket get --namespace MyNamespace --name MyBucket

oci os bucket get --namespace axzt5tlh3ol3 --name bucket-test		

Use the oci os bucket update command to enable versioning:

oci os bucket update --namespace mynamespace --name bucketname --versioning [text]
oci os bucket update --namespace axzt5tlh3ol3 --name bucket-test --versioning Enabled

Upload an empty text file to the bucket and inspect its generation number:

touch plan.txt
 oci os object put --file /home/aliciathom/images/plan.txt --namespace axzt5tlh3ol3 --bucket-name bucket-test

To see the version number assigned to the file:

oci os object head --namespace <object_storage_namespace> --bucket-name <bucket_name> --name <object_name>
oci os object head --namespace axzt5tlh3ol3 --bucket-name bucket-test --name plan.txt

Upload a new version of plan.txt and see the new version ID:

From GUI you can also see all versions:

We hope you enjoyed this post! If you like it or want us to include more information click the button below to send us your comments. Thanks!!

Reference Documents

Object Versioning

Managing Objects

OCI CLI Command Guide