Don’t want to spend time trying to find the compartment ID in OCI CLI? Jq to the rescue!

If you’re using OCI CLI, you probably have realized compartment ID is a big thing. It’s needed in many of the commands, and sometimes it’s a pain to go find the compartment you’re looking for if you have many compartments.

Jq is the solution here, just like it’s the solution the almost every CLI related problem in the world.

Here’s a little helper function that will print the ID of the compartment name you passed as a parameter:

function fcid() {
oci iam compartment list --all | jq -r ".[] | .[] | select(.name==\"$@\") | .id"
}