When was file last accessed?

I know one can get info on file creation date; but can one find out when a particular file(s) have last been accessed?  I want to cron a proceedure to rm certain files not accessed for a predetermined amount of time.
Who is Participating?
kiffneyConnect With a Mentor Commented:
Yes, instead of -atime use -amin and put in +100 for files not accessed for the past 100 minutes.  
RUSTYAuthor Commented:
Adjusted points from 50 to 100
if you're using gnu find, you could do

find /path/to/files -name '*' -atime +100

to find files that have not been accessed for more than 100 days.  If you added

|xargs rm -f

to the end of that line, that will delete them.  Use this with care, and remember that find descends the directory tree unless you also specify -maxdepth.

ls -u gives you that type of information.


find <dir> -type f -atime +3 | xargs rm

should remove all files not accessed in the last 3 days. Check it with man find, though it's untested code - I use something similar, but with -mtime (last modified).


RUSTYAuthor Commented:
Cool.  one problem: I'll be looking at files not accessed a certain amount of minutes or hours ago.  Is that feasable?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.