• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

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.
0
RUSTY
Asked:
RUSTY
  • 2
  • 2
1 Solution
 
RUSTYAuthor Commented:
Adjusted points from 50 to 100
0
 
kiffneyCommented:
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.
0
 
alien_life_formCommented:
Greetings.

ls -u gives you that type of information.

Also:

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

Cheers,
   alf

0
 
RUSTYAuthor Commented:
Cool.  one problem: I'll be looking at files not accessed a certain amount of minutes or hours ago.  Is that feasable?
0
 
kiffneyCommented:
Yes, instead of -atime use -amin and put in +100 for files not accessed for the past 100 minutes.  
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now