I want to make room in my OS X hard drive by identifying and removing "dead wood", i.e. files that have not been used in a long time (say, longer than 2 years).

Is there a general tool for identifying old, unused files?

(Note 1: I know of a tool for removing localization files, but I am looking for something far more general than that. Likewise, I know of tools of to identify large files, but this is not what I am looking for at the moment.)

(Note 2: I'm not interested in a tool thst automatically deletes the old, unused files it finds; I want to be able scan the list of candidate files, and remove any that I want to keep despite their being old and inactive.)



Using mdfind (Spotlight)

As OS X indexes everything using Spotlight, you have a very powerful command line tool to find what you need:

mdfind -onlyin <directory> 'kMDItemLastUsedDate <= $time.today(-<days>)'

would for example list everything in <directory> that you haven't opened for <days>. You can of course leave out the onlyin if you want to search system-wide. I'd recommend however to look in specific directories.

You can modify this query with:

  • $time.this_week
  • $time.this_month
  • $time.this_year

and of course also add $time.this_week(-5), for example, if you want something that hasn't been opened for 5 weeks. Or, in your case, using $time.this_year(-2) for something that wasn't used in the last two years.

Also, you can access other attributes:

  • kMDItemContentModificationDate (when it was modified)
  • kMDItemContentCreationDate (when it was created)

There are a number of other queries you can make. See here for a list of other attributes.

Using find

A simple listing of files in <directory> that have been modified more than <d> days ago:

find <directory> -type f -mtime +<d>

So, for example

find ~/Documents -type f -mtime +150

lists all your files in ~/Documents that you haven't modified for at least 150 days.

mtime is the Unix modification time of a file which is not changed when you (or the system) reads it. Conversely, if you want to list files that have been modified within the last 150 days, you would use -150 instead of +150.

Just like mtime, there is also atime, which designates the last access time. Same syntax:

find ~/Documents -type f -atime +150

But I'm not too sure it's too precise. At least on OS X, Spotlight seems to be the better option here.

  • This is likely going to select hundreds of system-files that are read, not modified.
    – pberlijn
    May 17 '11 at 15:38
  • No, that's what the mtime is for ("modified" time). Reading a file doesn't change its mtime.
    – slhck
    May 17 '11 at 15:40
  • Yes, that was my point. It seems that he is asking to delete files that have been 'unused'. Reading a file is still using it. Ergo, mtime does not find 'unused' files.
    – pberlijn
    May 17 '11 at 15:44
  • @pberlijn Oh, right. Updated my answer.
    – slhck
    May 17 '11 at 16:02

To do this in Finder, select the folder you want to search (e.g. your home directory) and press Cmd-F.

Hold down Option and click the ... button (which is a + button when you don't press Option) to the right of the predicate editor (the bar with the search criteria).

Select none where it says any for the new criteria block, and select either Last Opened Date (probably the default) or Last Modified Date in the next line. Then, enter your desired time range. It should look somewhat like this:

enter image description here

You don't need to actually enter a search expression, it'll just list the files that haven't been modified in some time.

Doing this from Finder has the advantage that it's very easy to add additional criteria, and to sort and view the resulting files.

See this answer on how to add the size column to the Spotlight results list to selectively delete old and large files.

  • Oh, +1. I'm so hooked on the Terminal that I forgot it has this UI feature. D'oh.
    – slhck
    May 17 '11 at 17:29
  • @slhck Thanks. It's easy to forget that though ;) —— Could you check that Last Opened Date is broken (at least with this method)? I find several more recent files, that were written but never opened again. The Last Opened column says today though, but it's a result anyway.
    – Daniel Beck
    May 17 '11 at 17:37
  • @Daniel I'm not 100% sure but judging from all I've tried the results seem reasonable. At least I'd consider them useful :)
    – slhck
    May 17 '11 at 18:14
  • @slhck So you don't have this problem?
    – Daniel Beck
    May 17 '11 at 18:39
  • 1
    @slhck Well I'm not too concerned about the value in the list, more that they're in the results list. Also, you'd expect them to disappear once you add the Last Modified criterium, but they still show up. Remove Last Opened (leaving only Last Modified) and they disappear. It appears that Last opened date is ridiculously useless.
    – Daniel Beck
    May 17 '11 at 18:56


Enter some wildcard for the type of files you want to delete (or a general wildcard), and add the attribute 'Last opened date'. Set this to your liking.

Be careful what you delete.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.