Courseiva
Shells, Scripting and Data ManagementmediumMultiple ChoiceObjective-mapped

LPIC-1 Shells, Scripting and Data Management Practice Question

A log file access.log contains multiple entries per IP address. An administrator wants to display a list of unique IP addresses sorted by frequency (most frequent first). Which command pipeline achieves this?

⚠ Common exam trap

The trap here is that candidates often forget uniq -c outputs the count in the first column, so they mistakenly use sort -k2 to sort by frequency, or they omit the initial sort before uniq, causing incorrect counts for non-consecutive duplicates.

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

awk '{print $1}' access.log | sort | uniq -c | sort -rn

It extracts the first field (IP address) with awk, sorts them to group identical IPs, counts occurrences with uniq -c, and then sorts numerically in reverse order with sort -rn to display the most frequent IPs first. The -c flag prepends a count to each unique line, and sort -rn sorts by that count descending.

Answer analysis

Option-by-option breakdown

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

  • awk '{print $1}' access.log | sort | uniq | sort -rn

    Why it's wrong here

    Shows unique IPs sorted in reverse numeric order of IP, not by frequency.

  • awk '{print $1}' access.log | sort | uniq -c | sort -rn

    Why this is correct

    Correctly counts IP occurrences and sorts by frequency descending.

  • awk '{print $1}' access.log | sort -rn | uniq -c

    Why it's wrong here

    Sorts IPs in reverse before counting, which breaks grouping; uniq requires adjacent duplicates.

  • awk '{print $1}' access.log | sort | uniq -c | sort -k2

    Why it's wrong here

    Sorts by the second field (IP), not by frequency count.

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.