Setting default values for the OCI Command Line

Tom MooreTom Moore
4 min read

The OCI Command Line is a great tool for getting certain tasks done. In some cases the Command line exposes functionality that is either not available in the console, or is harder to achieve in the console. And quite frankly if you work in the cloud at all, having the vendor’s command line installed should be considered a requirement.

A lot of command ins the OCI CLI require you to specify a compartment, or a namespace. If you are regularly interacting with the same compartment, and leveraging the same namespace for things like Object storage, this can get a little tedious, especially since the CLI requires you to specify the OCID of your compartment. Given that my short term memory does not allocate space for 79 character ID’s this means going and looking up the OCID every time…

Except… You don’t have to! I am about to share the best quality of life mod that you can leverage when it comes to the OCI CLI.

The OCI command line allows you to set command line defaults, in a separate file.

Create a file called oci_cli_rc alongside your OCI Configuration file. In m case this is at

~/.oci/oci_cli_rc

Inside that file you can create a default profile and add lines that specify the options that you normally add to the command line.

[DEFAULT]
compartment-id = ocid1.tenancy.oc1..XXXXXXXXXXXXXXXXXXXXXXXXXX
namespace-name = XXXXXXXXXXX

Now when I use the command line, I can omit the —compartment-id and —namespace-id options, and the CLI will fill them in automatically.

[opc@lancedb ~]$ oci os bucket list
{
  "data": [
    {
      "compartment-id": "ocid1.tenancy.oc1..XXXXXXXXXXXXXXXXXXXXXXXXXX",
      "created-by": "ocid1.user.oc1..XXXXXXXXXXXXXXXXXXXXXXXXXX",
      "defined-tags": null,
      "etag": "31d1ec94-deca-45bd-868a-19a14fcd2aed",
      "freeform-tags": null,
      "name": "sample-bucket",
      "namespace": "XXXXXXXXXXX",
      "time-created": "2025-08-14T19:03:59.366000+00:00"
    },
    {
      "compartment-id": "ocid1.tenancy.oc1..XXXXXXXXXXXXXXXXXXXXXXXXXX",
      "created-by": "ocidv1:loggingvrp:oc1:iad:loggingvrpgingvrp:XXXXXXXXXXXXXXXXXXXXXXXXXX",
      "defined-tags": null,
      "etag": "f84c3e0a-1aaf-4109-a3dd-ec3efa4f33eb",
      "freeform-tags": null,
      "name": "oci-logs._flowlogs.ocid1.tenancy.oc1..XXXXXXXXXXXXXXXXXXXXXXXXXX",
      "namespace": "XXXXXXXXXXX",
      "time-created": "2025-05-14T00:42:19.328000+00:00"
    }
  ]
}

This option works great, if you are primarily working in a single compartment, but what happens if you work across multiple compartments? The answer is actually quite simple, profiles.

First up I have my OCI Config file:

[DEFAULT]
user=ocid1.user.oc1..XXXXXXXXXXX
fingerprint=XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX
key_file=/home/opc/.oci/oci_api_key.pem
tenancy=ocid1.tenancy.oc1..XXXXXXXXXXX
region=us-ashburn-1

[functions]

Notice that I have the [DEFAULT] profile, and an empty [functions] profile.

Now, in my oci_cli_rc file, I have:

[DEFAULT]
compartment-id = ocid1.tenancy.oc1..XXXXXXXXXXX
namespace-name = idkdtvnsgvin


[functions]
compartment-id = ocid1.compartment.oc1..XXXXXXXXXXX

At the command line I can type:

oci os bucket list

And I will get the list of buckets from my root container. (The values configured in my default profile.)

However if I type:

oci os bucket list --profile functions

The magic happens. First off, because my config file has an empty [functions] profile, the command line automatically uses the values from my default profile to find my OCI Tenancy. Then the command line heads over to my oci_cli_rc file. From the oci_cli_rc file, the cli will grab the compartment-id from the [functions] profile, and because the [functions] profile doesn’t have the namespace defined, the namespace-id gets pulled from the [DEFAULT] profile.

There are ways to start creating different combinations between the config and rc files, but the easiest, and and most straight forward way is to simply keep the names the same across the two files.

Command Aliases

If you are setting up your oci_cli_rc file, you might also want to add some helpful shortcuts as well in the form of aliases.

For example, I naturally think “ls” to list things instead of “list” which for me means a lot of messages that look like this:

[opc@lancedb ~]$ oci os bucket ls
Usage: oci os bucket [OPTIONS] COMMAND [ARGS]...

Error: No such command 'ls'.

Once again the rc file can come to the rescue!

[OCI_CLI_COMMAND_ALIASES]
ls = list

Adding the above line to your RC file enables you to type:

oci os bucket ls

And in fact any command where you would type “list” is now enabled with support for “ls”

The official OCI command line documentation I found slightly confusing as it appeared to me that the [OCI_CLI_COMMAND_ALIASES] section went into your config file, however it goes in your RC file.

The full documentation can be found Here

I hope this helps make your CLI use a little more friendly!

0
Subscribe to my newsletter

Read articles from Tom Moore directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Tom Moore
Tom Moore

I am a Master Principal Cloud Architect for Oracle Cloud (OCI). I create content designed to help developers with Cloud-Based technologies. This includes AWS, OCI, and occasionally Azure. I'm not excluding GCP, I just haven't had any excuse to dive into GCP yet. As far as development is concerned, my area of focus is predominantly .NET, though these days, I do branch out occasionally into NodeJS and Python. I am available for in-person speaking events as well as virtual sessions. I can usually be found at Boston Code Camp. Opinions expressed on my blog are my own, and should not be considered to be the opinions of my employer.