Courseiva
Essential Commands →hardMultiple Choice

LFCS Essential Commands Practice Question

An administrator needs to combine two sorted text files, /tmp/a.txt and /tmp/b.txt, into a single sorted stream on standard output while also removing duplicate lines that appear in both files. Which command should be used?

⚠ Common exam trap

The trap here is assuming uniq can accept two files and merge them, when its second argument is an output file.

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

✓

sort -u /tmp/a.txt /tmp/b.txt

Sorting both files together with duplicate suppression yields the union of their lines in order, which matches the request. Merge mode preserves duplicates, uniq cannot read two inputs and would clobber the second path, and comm -12 returns only the shared lines, so none of those alternatives produce the required combined, deduplicated stream.

Answer analysis

Option-by-option breakdown

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

  • ✗

    sort -m /tmp/a.txt /tmp/b.txt

    Why it's wrong here

    The -m option merges already-sorted inputs efficiently but does not remove duplicate lines; any line present in both files appears twice in the output. Since the requirement explicitly includes eliminating duplicates, merge-only behavior leaves the task incomplete even though the ordering is correct.

  • ✗

    comm -12 /tmp/a.txt /tmp/b.txt

    Why it's wrong here

    comm -12 prints only lines common to both files, that is the intersection, and it discards lines unique to either file. The administrator wants a union with duplicates removed, not an intersection, so this command silently drops most of the desired content.

  • ✓

    sort -u /tmp/a.txt /tmp/b.txt

    Why this is correct

    Passing both files as arguments to sort merges them into one input stream, and -u suppresses duplicate lines after sorting. Because the input files are already sorted, the result is a single ordered stream with duplicates from either file removed, which is exactly the stated goal.

  • ✗

    uniq /tmp/a.txt /tmp/b.txt

    Why it's wrong here

    uniq accepts a single input file and an optional output file, so the second argument is treated as the output destination rather than a second input. It would read only the first file, collapse adjacent duplicates there, and overwrite the second file, which is both incorrect and destructive.

About these practice questions

This LFCS question is part of Courseiva's 406-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 Linux Foundation exam blueprint

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.