Courseiva
Automation, Orchestration, and ScriptinghardMultiple ChoiceObjective-mapped

XK0-006 Automation, Orchestration, and Scripting Practice Question

An administrator is writing a bash script that loops through all .log files in /var/log and prints the file name if the file is larger than 100 kilobytes. Which loop correctly implements this?

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/log -name '*.log' -size +100k -exec echo {} \;

The find command with -size filters files larger than 100k, and -exec with {} runs the command for each file. The other options have syntax errors or incorrect logic.

Answer analysis

Option-by-option breakdown

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

  • ls -l /var/log/*.log | awk '$5>100 {print $NF}'

    Why it's wrong here

    This works for some cases but may fail with spaces in filenames or if ls output changes.

  • for f in /var/log/*.log; do if [ -s $f -a $(stat -c%s $f) -gt 100 ]; then echo $f; fi; done

    Why it's wrong here

    -s checks if file is non-empty, not size; -gt compares numbers but stat output may cause issues.

  • find /var/log -name '*.log' -size +100k -exec echo {} \;

    Why this is correct

    Correct. find with -size +100k matches files larger than 100 kilobytes.

  • for f in /var/log/*.log; do if [ $f -gt 100k ]; then echo $f; fi; done

    Why it's wrong here

    The test command cannot compare file sizes directly; -gt is for integer comparison.

About these practice questions

This XK0-006 question is part of Courseiva's 979-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This XK0-006 practice question is part of Courseiva's free CompTIA 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 XK0-006 exam.