Friday, August 5, 2011

Cleaning Up Lightroom Previews


To get the fastest possible speed with Lightroom, I use an Intel X25M SSD to store my Lightroom catalog together with the previews.  The downside to this idea, is that SSDs are expensive.  To keep costs in line, I purchased a small-ish 120Gb drive (that is, it is "small" compared to any regular hard drive in my system, most of which are 2Tb drives).

And it seemed like, over time, the more pictures I took, the less disk space I had available on my SSD.  To the point that I was starting to get worried about it filling up (meanwhile, my Lightroom Catalog was still only 6Gb in size, so I knew it wasn't chewing up all of the space).

Lightroom has an option to limit the size of the Camera Raw Cache (Edit | Preferences | File Handling | Camera Raw Cache Settings) which I also store on the SSD.  There is a purge button on that screen and I would click it from time to time and watch my space free up again.  But it was never really quite the same.  The free space still keep getting lower and lower.

Lightroom also has an option to discard 1:1 previews (Edit | Catalog Settings | File Handling | Automatically Discard 1:1 Previews) after One Day, One Week, 30 Days or Never.  I had it set to One Day and yet my disk space STILL kept dropping.

Lightroom also has an option to optimize the catalog (File | Optimize Catalog).  I have no idea what this does.  It is said to "speed up" the catalog.  I try it from time to time.  But the catalog never really feels slow to me.  And optimizing also doesn't appear to free up much space.


Well...  I discovered tonight that I had almost 134,000 files in my Lightroom "previews" folder, taking up just over 94Gb of disk space.  And I thought to myself ... how many of those files do I really need???

If a photo shoot is more than 6 months old, maybe I don't need quick access to the previews any more.  What if I delete those files?  (For the wary: Lightroom will automatically rebuild a preview the moment you try to view the file, so this is not dangerous in any way, all I'm doing is trading speed for disk space)

I discovered tonight that Windows 7 has a command called ForFiles that can be run in a batch file.  So I created the following file:

forfiles -p "d:\users\dwt\pictures\lightroom\Lightroom 3 Catalog-2 Previews.lrdata" -s -m *.lrprev -d -180 -c "cmd /c del @path" 
(all of the above fits on one line in the batch file)

I ran the above command file and my free space jumped from about 4Gb to over 57Gb (having deleted over 52,000 files).  Here's an explanation for what the above command is doing:

ForFiles is the command, the following are the parameters:
-p specifies the root path of the previews
-s tells it to scan subdirectories as well
-m is a filename mask (I used *.lrprev so that only Lightroom Preview files would be deleted)
-d specifies the number of days (-180 tells it to use today's date minus 180 days)
-c "cmd /c del @path" tells it to run the cmd process passing in the command "del @path" for each file found (@path is expanded to the full path and filename of the file found)

If you want to try creating the above command file and test it first without deleting anything... an easy modification would be to change "del" to "dir".  That way when you run the command you will see a list of each of the files found rather than deleting each of the files found.

Be sure to change the path (-p parameter) to match the location for YOUR previews.

Now whenever I want to free up disk space all I have to do is run this command file.  Super easy!  And if I want even more space,  all I really have to do is decrease the number of days (say to -90 instead of -180).

ON A HAPPY NOTE: I found that the catalog itself embeds a thumbnail of each image.  It's not very high resolution.  But it does mean that after deleting the previews and before Lightroom has a chance to regenerate them - if I jump into a folder that I want to see what it is, the thumbnails can help me figure it out quickly.

For Mac users - I have no idea what utilities are available for deleting files by date.  But the idea should be the same.  Feel free to delete your previews, they will come back when you need them.


Jeremy Nicoll said...

Since OS X is built on flavor of Linux, the answer is finding a Bash command that'll do the same thing. I found the following command at this site:

find /path/to/files* -mtime +5 -exec rm {} \;

dterryphotography said...

Thanks Jeremy! :)

Anonymous said...

This was helpful. Thanks for posting this info.

Valerie said...

Thanks for sharing, David! I was looking for a way to deal with it because I had over 100GB of preview files. I wasn't sure if it was okay to just delete them.

dterryphotography said...

The only side effect to deleting the previews is that next time you look at the images in Lightroom the preview will be blank. As long as the image is still in the same location (or as long as you reattach the image) Lightroom will automatically regenerate the previews. No harm done!

Lee said...

Genius! Thank you :)

Unknown said...

I dont get it David.

I have my preview file at this location,
g:\Backup Bilder\Lightroom bilder\Lightroom\Lightroom 5 Catalog Previews.lrdata

That is external HD and i'm running win 7.

This is how i tried,

forfiles-g"d:\Backup Bilder\Lightroom bilder\Lightroom\Lightroom 5 Catalog Previews.lrdata"-s-m*.lrprev-d-180-c"cmd/cdir@path”

Pls help, dont know what i'm doing wrong.


dterryphotography said...

Make sure the letters and spacing are correct. I see the lack of spaces in your example as well as incorrect letters. Here is my current command line:

forfiles -p "d:\users\dwt\pictures\lightroom\Lightroom 5\Lightroom 5 Previews.lrdata" -s -m *.lrprev -d -60 -c "cmd /c del @path"

Robert Cain said...

Great, from 179GB of data to 1.1 GB. I'll share this with friends. Thanks for automating this effort.

joshuadwagner said...

Hi, thanks for this idea. I went through and manually deleted a whole bunch of folders inside the previews.lrdata package. (I'm on a mac) Unfortunately the size of the package still appears to be the same, even though I have deleted the files, emptied the trash, and restarted my laptop.

I'm not sure if it's finder that needs a refresh but I did delete the hidden .ds_store file and that didn't make a difference.

I wonder if it's that the package has a set size that needs to be adjusted somehow, similar to how a sparsebundle has a set size but can be adjusted? Any ideas?