TIMEX
TIMEX

Reputation: 271744

In my Apache2 access.log, how do I filter what gets displayed?

Someone told me to do this in order to keep track of latest people hitting my server:

tail -f access.log

However, this shows all the "includes", including the JS file, the graphics, etc. What if I just want to see the pages that people hit? How do I filter that using tail -f?

Upvotes: 1

Views: 1223

Answers (2)

Matthew
Matthew

Reputation: 1875

You can pipe the output through grep or awk. For example, if all your pages have .php in the URL, you can try the following:

tail -f access.log | grep '\.php'

If your access logs include a referrer field, the above will also match many resources. We're only interested in events with .php in the request field, not the referrer field. By using awk, we can distinguish between these.

tail -f access.log | awk '$7 ~ /\.php/ { print }'

You may need to adjust $7 if your log format is unusual.

Upvotes: 1

Mike Sherov
Mike Sherov

Reputation: 13427

if you're serving .php files:

tail -f access_log | grep ".php"

alternatively, if all your includes are in a folder named "include", for example:

tail -f access_log | grep "include" -v

or if you want to count hits to a certain file:

grep "filename" access_log -c

Upvotes: 0

Related Questions