Courseiva
Essential Tools →mediumMultiple Choice

EX200 Essential Tools Practice Question

A user wants to display the contents of a file in reverse line order. Which command should be used?

⚠ Common exam trap

Candidates often confuse `tac` with `tail` or `rev`, or incorrectly assume `sort -r` reverses line order, when in fact `tac` is the specific command for reversing line order in a 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

✓

tac file

The `tac` command is the standard Linux utility for displaying a file in reverse line order. It reads the file from the last line to the first, effectively reversing the line sequence. This is the correct tool for the task described.

Answer analysis

Option-by-option breakdown

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

  • ✗

    tail -r file

    Why it's wrong here

    The -r option for tail is not a standard flag defined by POSIX or GNU coreutils. On a Red Hat Enterprise Linux system, `tail -r file` produces an invalid option error, and even on BSD variants where it exists, it is not a reliable cross-platform way to reverse line order. The purpose of tail is to output the last N lines of a file, not to invert the entire line sequence.

  • ✗

    sort -r file

    Why it's wrong here

    Rather than preserving the original line order and turning it upside down, `sort -r file` reorders every line into descending collating order. This means an unsorted file will come back alphabetically (or numerically) reversed, so the sequence is lost and the output is not simply the input read backward. Only if the input were already sorted would sort -r appear to reverse the file, which is not a general solution.

  • ✗

    rev file

    Why it's wrong here

    The `rev` utility operates on individual lines rather than the file as a whole, flipping the character sequence of each line from right to left. It outputs the same number of lines in the same order, but each line's contents are mirrored, so the first line stays first and the last line stays last. Therefore `rev file` does nothing to move the last line to the top, which is the defining requirement of displaying a file in reverse line order.

  • ✓

    tac file

    Why this is correct

    `tac` is the inverse of `cat` and writes each file to standard output with the lines listed in reverse order, meaning the last line appears first. The name comes from "cat" spelled backward, and it is a standard coreutils command available on RHEL. It preserves the exact content of every line while reversing only the line sequence, which exactly fulfills the user's request.

About these practice questions

One of 427 original EX200 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 EX200 practice question is part of Courseiva's free Red Hat 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 EX200 exam.