Courseiva

LPIC-1 Shells, Scripting and Data Management Practice Question

A backup script stores its log file path in the variable LOGFILE and needs to append a timestamp line to that file. Which command correctly appends the output of the `date` command to the file named in the variable?

⚠ Common exam trap

A common mix-up: candidates confuse `>` with `>>`; the single greater-than sign overwrites the file, silently destroying existing log data.

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

✓

date >> $LOGFILE

Appending output requires the `>>` redirection operator, which opens the destination file for appending rather than truncating it. With the variable expanded to the log path, `date >> $LOGFILE` adds a new timestamp line while keeping all previous entries intact, which is exactly what the backup script needs.

Answer analysis

Option-by-option breakdown

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

  • ✓

    date >> $LOGFILE

    Why this is correct

    The `>>` operator opens the file in append mode, adding the output of `date` to the end without erasing existing content. Because `$LOGFILE` expands to the stored path, the timestamp is appended to the intended log file. This satisfies the requirement of preserving prior log entries.

  • ✗

    date < $LOGFILE

    Why it's wrong here

    The `<` operator redirects standard input from the file, meaning `date` would try to read data from the log file instead of writing to it. `date` does not consume standard input for its normal output, so no timestamp is appended, and the log file is not modified.

  • ✗

    date | $LOGFILE

    Why it's wrong here

    A pipe sends the standard output of `date` into the standard input of the command named by `$LOGFILE`. Since the variable holds a file path rather than an executable, the shell will attempt to run the path as a command and fail; nothing is appended to the log file.

  • ✗

    date > $LOGFILE

    Why it's wrong here

    The single `>` redirection operator truncates the target file before writing, so any existing log contents would be destroyed. Since the requirement is to append a timestamp line while preserving earlier entries, this operator is the wrong choice even though the variable expansion itself is correct.

About these practice questions

This LPIC-1 question is part of Courseiva's 402-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official LPI exam blueprint

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.