Your company has dozens of Compute Engine virtual machines across multiple zones. For a maintenance report, you must quickly display only those VMs that
reside in zone us-central1-b,
have names that start with "web-", and
are currently in the RUNNING state. Which gcloud command meets all of these requirements in a single invocation?
gcloud compute instances list --filter="zone:us-central1-b AND name~'^web-' AND status=RUNNING"
gcloud compute instances list --zones us-central1-b --filter="name=web-* AND status=RUNNING"
gcloud compute instances list --filter="name ('web-*') AND zone=us-central1-b AND status:RUNNING"
gcloud compute instances list --filter="labels.name=web-* AND zone~us-central1-b AND status!=TERMINATED"
The gcloud compute instances list command supports an advanced --filter flag that accepts logical expressions on resource fields. A valid expression can combine multiple comparisons with the AND keyword:
zone:us-central1-b restricts results to instances whose zone string contains us-central1-b.
name~'^web-' uses the regular-expression operator (~) to match any instance name that begins with the literal characters web-.
status=RUNNING limits the list to VMs whose lifecycle status field equals RUNNING. Putting the three comparisons together with AND ensures that only running web-* instances in the specified zone are returned. The other commands are incorrect because they either use the wrong flag name for zone, misuse the filter grammar (such as the wildcard operator without =~ or ~), or separate the zone restriction from the filter, resulting in an incomplete or syntactically invalid filter.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does the '--filter' flag do in the gcloud command?
Open an interactive chat with Bash
What is the significance of the `name~'^web-'` in the filter?
Open an interactive chat with Bash
What does 'status=RUNNING' signify in this gcloud command?
Open an interactive chat with Bash
What is the purpose of the gcloud filter flag?
Open an interactive chat with Bash
What does the regex operator '~' do in gcloud commands?
Open an interactive chat with Bash
How does the AND keyword combine filter criteria?
Open an interactive chat with Bash
GCP Associate Cloud Engineer
Ensuring successful operation of a cloud solution
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99
$19.99/mo
Billed monthly, Cancel any time.
3 Month Pass
$44.99
$14.99/mo
One time purchase of $44.99, Does not auto-renew.
MOST POPULAR
Annual Pass
$119.99
$9.99/mo
One time purchase of $119.99, Does not auto-renew.
BEST DEAL
Lifetime Pass
$189.99
One time purchase, Good for life.
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .