views:

26

answers:

2

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?

+1  A: 

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.

Matthew
A: 

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
Mike Sherov