Courseiva

LPIC-1 Shells, Scripting and Data Management Practice Question

A directory contains files with spaces and special characters in their names. An administrator wants to delete all files older than 30 days using find and xargs. Which command is safe?

⚠ Common exam trap

A common mix-up: candidates choose option C, overlooking the fact that default xargs splits on whitespace and interprets quotes, making it unsafe for filenames with spaces or special characters, while `-print0` and `-0` are the correct safe approach.

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 /path -type f -mtime +30 -print0 | xargs -0 rm

It uses `-print0` with `find` to output null-delimited filenames, and `xargs -0` to process them safely. This handles spaces, newlines, and special characters in filenames without word-splitting or shell interpretation, ensuring all matching files older than 30 days are deleted reliably.

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 /path -type f -mtime +30 -delete

    Why it's wrong here

    find's -delete action removes each matched file directly, bypassing xargs entirely, so it handles spaces and special characters safely without word-splitting. It is tempting because it is concise, yet the question explicitly requires find piped to xargs, which -delete does not use.

  • ✗

    find /path -type f -mtime +30 -exec rm {} \;

    Why it's wrong here

    -exec rm {} \; passes each filename as a single argument to rm, so spaces and special characters are preserved correctly. It is tempting because it is the classic safe idiom, but the question specifies using find with xargs, and -exec does not invoke xargs at all.

  • ✗

    find /path -type f -mtime +30 | xargs rm

    Why it's wrong here

    Piping find output into xargs rm splits filenames on whitespace, so names containing spaces or special characters are broken into separate arguments and the wrong files are deleted. It is tempting because it is the shortest pipeline, and it would work correctly only when filenames contain no whitespace.

  • ✓

    find /path -type f -mtime +30 -print0 | xargs -0 rm

    Why this is correct

    The -print0 flag terminates each path with a NUL byte, and xargs -0 reads that delimiter, so filenames containing spaces or special characters are passed to rm intact rather than being split into separate arguments.

About these practice questions

One of 402 original LPIC-1 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 by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This LPIC-1 practice question is part of Courseiva's free LPI 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 LPIC-1 exam.