Today, I wanted to find out how many times a file had been downloaded from a web server. Without Google Analytics, it was time to pull out the big guns – grep.
The command I used was:
grep -o /e.js /var/log/lighttpd/access.log | wc -w
/e.js is the file I’m interested in, while access.log is the file.
The output of grep will be a long list of the string /e.js to indicate the matches. wc counts number of words. With the use of the pipe, you have a lovely quick command to find out how many times a file has been downloaded via your logs.