Operations 5 min read

Top 3 Command-Line Tricks to Analyze Apache Access Logs Quickly

Learn three powerful shell commands that reveal the most active IPs, the most requested URLs, and the largest files in an Apache access_log, helping you quickly detect anomalies, optimize resources, and improve site performance.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
Top 3 Command-Line Tricks to Analyze Apache Access Logs Quickly

1. Top 10 IPs by Access Count

When traffic spikes unexpectedly, the fastest way is to identify the IPs with the most requests and temporarily block them.

# cat access_log | cut -f1 -d " " | sort | uniq -c | sort -k 1 -n -r | head -10

2. Top 10 Most Requested URLs

Knowing which URLs receive the most hits helps target optimization efforts.

# cat access_log | cut -f7 -d " " | sort | uniq -c | sort -k 1 -n -r | head -10

3. Top 10 Largest Requested Resources

Large files can severely affect response time, so identifying them is essential.

# cat access_log | sort -k 10 -n -r | head -10

Command Explanation

The commands are chained with pipes (|) so the output of one becomes the input of the next.

cat : display file contents.

cut : select columns; -d " " sets space as delimiter, -f1 selects the first field.

sort : sort lines; -k chooses column, -n numeric sort, -r reverse order.

uniq : remove duplicate lines; -c prefixes each line with its occurrence count.

head : show the first N lines; -10 shows top 10.

Sample Log Entry

Example lines from an Apache access_log:

183.195.232.39 - - [28/Dec/2015:22:31:48 +0800] "GET /ui-nav.js HTTP/1.1" 304 -
183.195.232.39 - - [28/Dec/2015:22:31:48 +0800] "GET /ui-toggle.js HTTP/1.1" 304 -
183.195.232.38 - - [28/Dec/2015:22:31:48 +0800] "GET /ui-toggle.js HTTP/1.1" 304 -

Running the first command on this log yields the IPs with the highest request counts, demonstrating the step‑by‑step processing of cat, cut, sort, uniq -c, sort -k 1 -n -r, and head -10.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

OperationsApachelog analysisShell Commands
Java High-Performance Architecture
Written by

Java High-Performance Architecture

Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.