2

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.)

Thanks!

Michael S.
  • 4,217
kjo
  • 1,351

3 Answers3

5

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.

slhck
  • 235,242
3

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.

Daniel Beck
  • 111,893
0

Spotlight.

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.

pberlijn
  • 10,410