Courseiva
Shells, Scripting and Data ManagementhardMultiple ChoiceObjective-mapped

LPIC-1 Shells, Scripting and Data Management Practice Question

A script produces both standard output and error messages. An administrator wants to save the output to 'out.log' and the error messages to 'err.log', but also wants to see both on the terminal. Which command achieves this?

⚠ Common exam trap

Many exam-takers confuse `2>&1` (which merges stderr into stdout) with separate stream handling, leading them to pick options that either lose terminal output or fail to keep stdout and stderr in distinct files.

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

./script.sh > >(tee out.log) 2> >(tee err.log)

Uses process substitution to redirect stdout and stderr into separate tee commands, which both write to files and pass the streams through to the terminal. The syntax `> >(tee out.log)` redirects stdout to a tee process that writes to out.log and also echoes to the terminal, while `2> >(tee err.log)` does the same for stderr. This ensures both streams are saved to separate files and displayed on the terminal simultaneously.

Answer analysis

Option-by-option breakdown

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

  • ./script.sh 2>&1 | tee out.log 2>&1 | tee err.log

    Why it's wrong here

    Complex and does not separate streams; stderr gets merged into stdout repeatedly.

  • ./script.sh > >(tee out.log) 2> >(tee err.log)

    Why this is correct

    Uses process substitution to duplicate stdout to terminal and out.log, and stderr to terminal and err.log.

  • ./script.sh > out.log 2> err.log

    Why it's wrong here

    Saves output and errors to separate files but does not display anything on the terminal.

  • ./script.sh 2>&1 | tee out.log

    Why it's wrong here

    Merges stderr into stdout; both go to out.log and terminal, but errors are not separated.

About these practice questions

Courseiva writes every LPIC-1 question from scratch — 527 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or 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 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.