Courseiva
Shells, Scripting and Data ManagementhardMultiple ChoiceObjective-mapped

LPIC-1 Shells, Scripting and Data Management Practice Question

A script needs to remove all trailing whitespace (spaces and tabs) from each line of a file. Which sed command will accomplish this?

⚠ Common exam trap

It's easy for candidates to confuse the quantifiers '*' (zero or more) and '+' (one or more) or forget that sed's default BRE mode requires escaping the '+' quantifier, leading them to choose Option A which would not work as intended.

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

sed 's/[ \t]*$//'

The sed command 's/[ \t]*$//' uses a regular expression that matches zero or more spaces or tabs (the character class [ \t] followed by *) anchored at the end of the line ($) and replaces them with nothing, effectively removing all trailing whitespace. The * quantifier ensures that both single and multiple trailing whitespace characters are removed, and the $ anchor restricts the match to the end of the line only.

Answer analysis

Option-by-option breakdown

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

  • sed 's/[[:space:]]+$//'

    Why it's wrong here

    Needs -E for extended regex; in basic + is literal.

  • sed 's/[ \t]*//g'

    Why it's wrong here

    Removes all whitespace globally.

  • sed 's/^[ \t]*//'

    Why it's wrong here

    Removes leading whitespace.

  • sed 's/[ \t]*$//'

    Why this is correct

    Matches trailing spaces/tabs and replaces with nothing.

About these practice questions

One of 527 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.