2

As we move on with our content-based websites, lots of images get dumped in our images folder, but we rarely come across anyone that deletes their files once they do not need them, meaning that we end up with a huge list of images in one folder, which is very tricky to clean up.

Isthere a tool that allows me to find out if an image has been requested from the web in the last (n) months?

More generally, how do you take control of your images folders? What policy do you enforce on developers to clean up? What measures do you take in order to decide what goes and what stays if you end up with an out-of-control situation?

4 Answers 4

1

Does your web content management tool allow you to report on or query which images are linked in the site content? Or can you run a string search for image file extensions in the content pages? If so, that report combined with a list of the images from web server logs in the last 12 months (or longer depending on your site) should be enough to identify needed images. This assumes image file requests appear in your server logs. If you have a scripting environment available on the server then you could script the removal of images not included in those lists. You could also create a second folder and move all the needed images there, and do the rename you outlined.

Of course, take a backup or two first, and test it works!

Your other approach, depending on the size of the site, would be to add more storage. This might be cheaper and quicker than spending your time sorting through a bunch of image files. This also prevents any later issues where images were linked directly from other sites or associated with content that is important but infrequently used.

5
  • If you have no access (or desire) to parse server logs, then there's not likely going to be a reliable way of doing this. Apr 13, 2010 at 0:36
  • but server logs give me what information? when the images were last access by web? i can obtain them if they are helpful
    – Ayyash
    Apr 13, 2010 at 0:43
  • Depends on the logging level, but yes. The logs may well state that such-and-such user downloaded such-and-such image on such-and-such date. So you just search through the logs for any occurance of candidatefordeletion.jpg and if it doesn't show up, you're more confident it can be deleted. Alternatively, search through the websites actual HTML content to see if the image is linked anywhere. Assuming it's static. Apr 13, 2010 at 3:06
  • im trying to hunt down server logs but i dont know what to ask for exactly, is there a technical term to define these logs? when i asked our admins they didnt understand what i was talking about!
    – Ayyash
    May 10, 2010 at 21:31
  • These are the logs generated by the web server software. For example if it's Apache HTTPD then you're looking for access logs, and if it's Windows IIS then you might find them in \Windows\System32\LogFiles. If you have a load balancer or reverse proxy then you might also see the page requests in their logs.
    – William
    May 12, 2010 at 3:49
1

why not run a script on fixed intervals to check for the files last accessed status and delete them based on aging parameter?

you can evaluate the access time in unix like systems using find -atime <arg> where arg is number of days with +/- to mean more or less respectively

so you can feed the output of the find -atime +90 "*.jpg" for example to search for jpg images last accessed more than 90 days back to a for loop, where you feed it to a $f variable for example and loop on them with rm command

0

Two simple ways to do what you want.

  1. Parse the web server logs (e.g. using Perl) and build a list of files that have been accessed, then remove all the others. Not my preferred way of doing things.
  2. Parse the links on your web site (if the site is built in a way that makes this practical) and remove any files not linked to. Much preferred where this is feasible, as it takes into account rarely accessed content.
0

After hunting down the log files, turned out the main server IIS does not log any data due to performance issue, and some "politics"! ended up creating my own "watch" log, where i read all incoming requests, check if it is inside the images folder, and open a text file, add the image url, and the urlReferrer, after a months time, i was able to make an educated guess of which folders should go

thanks everyone for your input on this

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .