Courseiva
Essential CommandshardMultiple ChoiceObjective-mapped

LFCS Essential Commands Practice Question

An administrator needs to replace all occurrences of the string 'foo' with 'bar' in all files under /etc/config, but only in files ending with .conf. The replacement must be done in-place, and backup copies should be created with a .bak extension. Which command accomplishes this?

⚠ Common exam trap

Test-takers frequently confuse the syntax `-i .bak` (with a space, which is incorrect) with `-i.bak` (no space, which is correct), or they forget that `-i` without a suffix does not create backups, leading them to choose options that either fail or omit the required backup step.

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 /etc/config -name '*.conf' -exec sed -i.bak 's/foo/bar/g' {} +

It uses `sed -i.bak` which creates a backup file with the .bak extension before performing the in-place substitution, and the `find -exec ... +` variant efficiently processes multiple files at once. The `-i` option with an argument (no space) specifies the backup suffix directly, satisfying the requirement for backup copies.

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 /etc/config -name '*.conf' -exec sed -i .bak 's/foo/bar/g' {} +

    Why it's wrong here

    Incorrect syntax; -i requires extension immediately after.

  • find /etc/config -name '*.conf' -exec sed 's/foo/bar/g' {} \;

    Why it's wrong here

    Prints to stdout, no in-place modification.

  • find /etc/config -name '*.conf' -exec sed -i.bak 's/foo/bar/g' {} +

    Why this is correct

    -i.bak creates backup with .bak extension.

  • find /etc/config -name '*.conf' -exec sed -i 's/foo/bar/g' {} +

    Why it's wrong here

    Does not create backup files.

About these practice questions

One of 507 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 by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

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.