Link to home
Start Free TrialLog in
Avatar of phreakin
phreakin

asked on

Find Access Time Script

I am looking for a way to remove files that haven't been accessed in approx. 45 minutes that are located in a specific directory. I know I can use find with something but I am not sure what to use in conjunction with it.
Avatar of bira
bira

Hi

  Here is an example of using find with the parameters
you want.

To remove all files named a.out or *.o that have not been accessed for a week and that are not mounted using nfs, enter:

find / \( -name a.out -o  -name '*.o' \) -atime +7 ! -fstype nfs
-exec \ rm {} \;

Note:   The number used within the -atime expression is +7. This is
the correct entry if you want the command to act on files not accessed
for more than a week (seven 24-hour periods).
Avatar of phreakin

ASKER

Ok, but what about for 45 minues?
Unfortunatelly now i am at home, where a have no unix to
do some test.
 But i advise you to see man find for the parameters
 of this command.

  I have already used -atime because i needed to delete
a minimum of one day, not minutes as you want.

  Good luck
ASKER CERTIFIED SOLUTION
Avatar of griessh
griessh
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What about doing this, would it work?

find /directory -mmin +40 > temp.file
rm -r < temp.file
I haven't seen the -mmin option (what is your OS?), but the rm won't work.
If you have that -mmin, then do something like:
find /directory -mmin +40 -exec \ rm {} \;

======
Werner
The OS is HP-UX 10.24
Hi, it seems to be difficult (impossible?) to do something with find with smaller steps than one day, so I have another suggestion:
If you list the content of your directory with ls -lu, you will get the access time instead of modification time in the time column.  Futhermore, if you use ls -trlu the list will be sorted with the most recently accessed files at the bottom.
From here, you can probably make a script that analyzes the time colum and make the desired actions.
This question appears to have been abandoned. Your options are:
 
1.  Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you. You must tell the participants why you wish to do this, and allow for Expert response.
3.  Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4.  Delete the question. Again, you must tell the other participants why you wish to do this.
 
Please click this Help Desk link for Member Guidelines, Member Agreement and the Question/Answer process:  Click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues.
https://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp
 
PLEASE DO NOT AWARD THE POINTS TO ME.  
_________________________________________
------------>  EXPERTS:
 
Please leave any comments regarding this question here on closing recommendations if this item remains inactive another three days.
 
Thank you everyone.
 
Moondancer
Community Support Moderator @ Experts Exchange
Since we didn't get any feedback from the asker about the precision needed, I claim that I provided a working solution.

======
Werner
Thank you, Werner, and sorry for the delay.  This was finalized today.  There are just too many in my EE Inbox, all the time.  :)
Moondancer - EE Moderator
Don't feel sorry! My revenge is in CS already :-)

=======
Werner