Useful CLI Commands
Use the following list commands to view resources in a tenancy or compartment.
In all the following examples, environment variables $T
and $C
are set to tenancy OCID and compartment OCID, respectively.
List Compartments in a Tenancy
# list all compartments (OCID, display name, description) in tenancy $T
oci iam compartment list -c $T
# grep above command for important fields
oci iam compartment list -c $T | grep -E "name|description|\"id\""
List IAM Users
# lists all users (OCID, display name, description) in tenancy $T
oci iam user list -c $T
# grep above command for important fields
oci iam user list -c $T | grep -E "name|description|\"id\""
List IAM Groups
# lists all groups (OCID, display name, description) in tenancy $T.
oci iam group list -c $T
# grep above command for important fields
oci iam group list -c $T | grep -E "name|description|\"id\""
List Users in a Group
The following command is helpful for listing users in groups, especially users with administrative privileges. This command requires the OCID of the group whose users are listed.
# list users in group with OCID <GROUP_OCID>
oci iam group list-users -c $T --group-id <GROUP_OCID>
List Security Policies
# lists all policies (OCID, name, statements) in tenancy $T. Remove pipe to grep to get entire information
oci iam policy list -c $T
# grep above command for important fields
oci iam policy list -c $T | grep -E "name|Allow|\"id\""