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