Courseiva
Essential Commands →mediumMultiple Choice

LFCS Essential Commands Practice Question

A server's root filesystem is filling up. An administrator needs to find the largest regular files under /var, sorted from largest to smallest, while avoiding errors from unreadable directories that are not owned by the administrator. Which command is most appropriate?

⚠ Common exam trap

The trap here is using du, which reports directory totals, when the task specifically asks for individual regular files.

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

✓

find /var -type f -printf '%s %p\n' 2>/dev/null | sort -rn | head -n 20

The precise approach is to use find restricted to regular files, print size and path, discard error output, then sort numerically in reverse and take the top entries. This avoids directory totals and unreadable-path noise. Recursive ls parsing is unreliable, du shows directory aggregates, and searching only directories answers a different question.

Answer analysis

Option-by-option breakdown

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

  • ✓

    find /var -type f -printf '%s %p\n' 2>/dev/null | sort -rn | head -n 20

    Why this is correct

    find with -type f restricts results to regular files, -printf outputs size in bytes followed by the path, and redirecting stderr suppresses permission errors from unreadable directories. Piping to sort -rn and head yields the largest files first, exactly matching the scenario's requirements.

  • ✗

    find /var -type d -exec du -sh {} + | sort -rh

    Why it's wrong here

    This limits find to directories and reports their total sizes, so it identifies the largest directories rather than the largest regular files. The scenario explicitly asks for regular files, and this command also produces permission errors that are not redirected, adding noise to the output.

  • ✗

    du -ah /var | sort -rh | head -n 20

    Why it's wrong here

    du reports disk usage per directory and file, which is useful, but the -a option lists every entry and the pipeline can be noisy and slow on a large tree. It also does not specifically isolate regular files and may include directory totals, making it less precise for identifying the largest individual regular files.

  • ✗

    ls -lR /var | sort -k5 -n | tail -n 20

    Why it's wrong here

    Recursive ls output is hard to parse reliably because it includes headers and non-file lines, and permission errors are printed to the terminal rather than suppressed. Sorting by the fifth column is fragile across locales and does not guarantee only regular files are considered, so the result may be misleading.

About these practice questions

One of 406 original LFCS practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official Linux Foundation exam blueprint

This LFCS practice question is part of Courseiva's free Linux Foundation 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 LFCS exam.