Question 50 of 537
Create simple shell scriptsmediumMultiple ChoiceObjective-mapped

Parsing df Output Reliably: Avoid Human-Readable Pitfalls

This EX200 practice question tests your understanding of create simple shell scripts. Read the scenario carefully and evaluate each option against the stated constraints before committing to an answer. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.

An administrator writes a script to check disk usage and send an alert if usage exceeds 80%. The script uses 'df -h /' and parses the output. To maintain portability and avoid common pitfalls, which approach is recommended?

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Use 'df / | awk 'NR==2 {print $5}' | tr -d '%'

Option C is correct because it uses `df /` (without `-h`) to produce a stable, machine-parseable output where the fifth field (`$5`) is always the percentage used, and `awk` reliably extracts it. The `tr -d '%'` removes the percent sign for numeric comparison. This approach avoids the portability issues of parsing human-readable output from `df -h`, which can vary in column spacing and ordering across different Unix/Linux systems.

Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Use 'df -h / | tail -1 | sed 's/.* //' | tr -d '%'

    Why it's wrong here

    Option A is fragile because it parses the human-readable output from 'df -h' with sed. The formatting of 'df -h' can vary across systems; for example, the percentage field may not be the last field, or there may be multiple spaces, making 's/.* //' unreliable. Additionally, using 'tail -1' assumes the output has only two lines, which may not hold if there are multiple mount points in /? This approach is not portable.

  • Use 'df -h / | tail -1 | cut -d' ' -f5'

    Why it's wrong here

    This option also uses `-h` and attempts to use `cut` with space delimiter. However, `df -h` output may have multiple spaces or different column ordering, so `cut -d' ' -f5` may not always extract the correct field. This is unreliable for portability.

  • Use 'df / | awk 'NR==2 {print $5}' | tr -d '%'

    Why this is correct

    This option uses `df /` without `-h`, which produces a stable, machine-parseable output. The `awk` command extracts the fifth field (the percentage used) and `tr` removes the percent sign. This is portable across different Unix/Linux systems.

    Related concept

    Read the scenario before looking for a memorised answer.

  • Use 'df -h / | grep -oP '\d+%'

    Why it's wrong here

    This option uses `df -h` and `grep` with a Perl regex to extract digits followed by '%'. While it may work on some systems, the human-readable output can vary, and the regex might not match all cases (e.g., if the percentage is like '100%' or has a leading space). It is less reliable than the approach in C.

Common exam traps

Common exam trap: answer the scenario, not the keyword

The trap on the RHCSA exam is that candidates assume `-h` is always better for readability, but the exam tests understanding that human-readable output is unreliable for scripting due to inconsistent column formatting across different Unix/Linux distributions.

Trap categories for this question

  • Command / output trap

    Option A is fragile because it parses the human-readable output from 'df -h' with sed. The formatting of 'df -h' can vary across systems; for example, the percentage field may not be the last field, or there may be multiple spaces, making 's/.* //' unreliable. Additionally, using 'tail -1' assumes the output has only two lines, which may not hold if there are multiple mount points in /? This approach is not portable.

Detailed technical explanation

How to think about this question

The `df` command without `-h` outputs fixed-width columns with the percentage in the 5th field, making it safe for `awk` parsing. The `-h` flag triggers human-readable formatting that can vary between systems (e.g., different units, alignment), breaking scripts that rely on column positions. In real-world automation, using `df --output=pcent /` (on GNU coreutils) is even more portable, but `df / | awk 'NR==2 {print $5}'` is a classic POSIX-compliant pattern.

KKey Concepts to Remember

  • Read the scenario before looking for a memorised answer.
  • Find the constraint that changes the correct option.
  • Eliminate answers that are true in general but not in this case.

TExam Day Tips

  • Watch for words such as best, first, most likely and least administrative effort.
  • Review why wrong options are wrong, not only why the correct option is correct.

Key takeaway

Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Real-world example

How this comes up in practice

A practitioner preparing for the EX200 exam encounters this exact type of scenario on the job. The correct answer here is not the most general option — it is the best answer for the specific constraint described. Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option. Real exam questions reward reading the full scenario before eliminating options, because the constraint defines which answer fits.

What to study next

Got this wrong? Here's your next step.

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

Related practice questions

Related EX200 practice-question pages

Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.

Practice this exam

Start a free EX200 practice session

Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.

FAQ

Questions learners often ask

What does this EX200 question test?

Create simple shell scripts — This question tests Create simple shell scripts — Read the scenario before looking for a memorised answer..

What is the correct answer to this question?

The correct answer is: Use 'df / | awk 'NR==2 {print $5}' | tr -d '%' — Option C is correct because it uses `df /` (without `-h`) to produce a stable, machine-parseable output where the fifth field (`$5`) is always the percentage used, and `awk` reliably extracts it. The `tr -d '%'` removes the percent sign for numeric comparison. This approach avoids the portability issues of parsing human-readable output from `df -h`, which can vary in column spacing and ordering across different Unix/Linux systems.

What should I do if I get this EX200 question wrong?

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

What is the key concept behind this question?

Read the scenario before looking for a memorised answer.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Keep practising

More EX200 practice questions

Last reviewed: Jul 4, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

This EX200 practice question is part of Courseiva's free Red Hat certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the EX200 exam.