Home / OCI

OCICheat sheetBeginner

OCI CLI essentials for daily operations

Set up the OCI CLI once, then use these commands to find resources across compartments, start and stop instances, and script output with JMESPath.

Deepak Bhardwaj2 min read

Applies toOCI CLI 3.x

Setup and authentication

oci setup config                       # creates ~/.oci/config and an API signing key
oci iam region list --output table     # quick auth check
# On an OCI VM with a dynamic group + policy, skip keys entirely:
export OCI_CLI_AUTH=instance_principal

Use a separate profile for each tenancy or region with --profile PROD, or set OCI_CLI_PROFILE.

Tip

Put defaults such as compartment-id in ~/.oci/oci_cli_rc so you don't have to paste OCIDs every time: oci setup oci-cli-rc.

Find things

# All compartments in the tenancy (nested)
oci iam compartment list --compartment-id-in-subtree true --all \
  --query "data[?\"lifecycle-state\"=='ACTIVE'].{name:name,id:id}" --output table

# Resource Search across ALL compartments - the fastest way to locate anything
oci search resource structured-search \
  --query-text "query instance resources where lifecycleState = 'RUNNING'" \
  --query "data.items[].{name:\"display-name\",compartment:\"compartment-id\"}" --output table

oci search resource free-text-search --text "app-prod-01"

Compute

C=ocid1.compartment.oc1..xxxx
oci compute instance list -c $C --all \
  --query "data[].{name:\"display-name\",state:\"lifecycle-state\",shape:shape,id:id}" --output table

oci compute instance action --action SOFTSTOP --instance-id $ID --wait-for-state STOPPED
oci compute instance action --action START    --instance-id $ID --wait-for-state RUNNING

# Private IP of an instance
oci compute instance list-vnics --instance-id $ID --query "data[0].\"private-ip\"" --raw-output

# Flex shape resize (instance reboots)
oci compute instance update --instance-id $ID --shape-config '{"ocpus":4,"memoryInGBs":64}'
Action Behavior
SOFTSTOP ACPI shutdown, so the OS shuts down cleanly
STOP Hard power off
SOFTRESET Graceful reboot
RESET Hard reboot

Networking checks

oci network vcn list -c $C --output table
oci network security-list list -c $C --vcn-id $VCN --query "data[].{name:\"display-name\",ingress:\"ingress-security-rules\"}"
oci network nsg rules list --nsg-id $NSG --all --output table

Work requests and audit

# Why is my operation still running / did it fail?
oci work-requests work-request list -c $C --query "data[?status!='SUCCEEDED']" --output table
# Who changed it?
oci audit event list -c $C --start-time 2026-10-14T00:00:00Z --end-time 2026-10-14T23:59:59Z \
  --query "data[?contains(\"event-type\",'instance')].{t:\"event-time\",who:data.identity.\"principal-name\",what:\"event-type\"}" --output table

Scripting tips

  • --all handles pagination. Without it you only get the first page.
  • --raw-output removes the quotes around single values, which is handy in shell variables.
  • --generate-full-command-json-input gives you a JSON template for complex create calls.
  • Each tenancy has service limits. Check them before a big scale-out with oci limits resource-availability get.