CompTIA Linux+ XK0-006 (V8) Practice Question

You are writing a portable Bourne-compatible shell script that must compress any log file in /var/log that exceeds 100 MiB (104 857 600 bytes). The loop must:

  1. Confirm that each entry is a regular file before acting.
  2. Compare the file's size against the byte threshold using POSIX-defined numeric operators.

Which snippet meets both requirements while remaining compatible with a standard /bin/sh on Linux?

  • for f in /var/log/*; do
      [ -f "$f" ] && [ $(stat -c%s "$f") -gt 104857600 ] && gzip "$f"
    done
    
  • for f in /var/log/*; do
      test -f "$f" && test $(stat -c%s "$f") > 104857600 && gzip "$f"
    done
    
  • for f in /var/log/*; do
      [[ -d "$f" ]] && [[ $(du -m "$f" | cut -f1) -gt 100 ]] && gzip "$f"
    done
    
  • for f in /var/log/*; do
      if (( $(stat -c%s "$f") > 104857600 )); then gzip "$f"; fi
    done
    
CompTIA Linux+ XK0-006 (V8)
Automation, Orchestration, and Scripting
Your Score:
Settings & Objectives
Random Mixed
Questions are selected randomly from all chosen topics, with a preference for those you haven’t seen before. You may see several questions from the same objective or domain in a row.
Rotate by Objective
Questions cycle through each objective or domain in turn, helping you avoid long streaks of questions from the same area. You may see some repeat questions, but the distribution will be more balanced across topics.

Check or uncheck an objective to set which questions you will receive.

Bash, the Crucial Exams Chat Bot
AI Bot