Pete Freitag Pete Freitag

Searching apache logs for iPhone User Agents

Updated on November 07, 2024
By Pete Freitag
apple

I was curious if anyone was using an iPhone to read my blog yet, I'm sure before too long we will all be optimizing our sites for 3.5" displays. To find out I did a little grep on my Apache log file and piped it to wc to count the number of matches:

grep 'iPhone;' access.log | wc -l

So far 370 hits including images, to take out requests for images I added:

grep 'iPhone;' access.log | fgrep --invert-match images | wc -l

That yields 106 requests, hello iPhone readers...

BTW the user agent for the iPhone looks like this:

Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3

Learn more about grep

There is a lot you can do with the grep linux command. Here, I'm using the --invert-match flag, which lets you perform a Inverted or Negative grep search. You can also do a case insensitive grep search, or even count files by extension using grep. Grep is one of the most useful linux commands to know!



iphone apple apache grep unix

Searching apache logs for iPhone User Agents was first published on July 19, 2007.

If you like reading about iphone, apple, apache, grep, or unix then you might also like:

Discuss / Follow me on Twitter ↯

Comments

Interesting... just went to my Google Analytics to search browsers. Searched for browsers containing "ipod", but nothing comes up. However, I did go to the site on someone's iPod (just to see what it looked like). So, not sure if Analytics is even picking them up. But then again, I just searched for MSIE and it came up with nothing, so I guess it is not storing useragents in that respect :(
by Ben Nadel on 07/20/2007 at 10:32:54 AM UTC
I measured our site's PDA traffic during the first week of the iPhone launch. As a whole PDAs accounted for only a very modest percentage of our site's total traffic.
The breakdown within that was:
29.1% Blackberry
28.4% Palm
25.2% WindowsCE
17.3% iPhone
17.3 % is pretty nice for a its first week on the market. I'll measure again in a few months is anyone's interested.
by Nick Rufa on 07/23/2007 at 10:42:33 AM UTC
Sorry, the numbers in my prev. post may be hard to follow. Trying again (29.1% Blackberry) . (28.4% Palm) . (25.2% WindowsCE) . (17.3 % iPhone)
by Nick Rufa on 07/23/2007 at 10:46:09 AM UTC
@Ben

Did you mean to say you searched for browsers containing "iPhone", either way it doesn't look like Google Analytics reports on iPhone's yet.
by Pete Freitag on 07/23/2007 at 11:30:06 AM UTC