Solved

Find Access Time Script

Posted on 2001-08-08
12
206 Views
Last Modified: 2013-12-06
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.
0
Comment
Question by:phreakin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
12 Comments
 
LVL 6

Expert Comment

by:bira
ID: 6365331
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).
0
 

Author Comment

by:phreakin
ID: 6365349
Ok, but what about for 45 minues?
0
 
LVL 6

Expert Comment

by:bira
ID: 6365491
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
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 11

Accepted Solution

by:
griessh earned 50 total points
ID: 6367830
phreakin

the -?time option is always using 24h steps, not quite what you are looking for. The better way might be the -newer <filename> option. It compares with the timestamp of an existing file (like "find \home\xxx -newer \home\test.file ! -exec \ rm {} \;") The problem is now to 'touch' the \home\test.file. I don't know how exact your 45 minutes have to be, but you could touch the file in a cronjob ...

Let us know ...

======
Werner
0
 

Author Comment

by:phreakin
ID: 6368145
What about doing this, would it work?

find /directory -mmin +40 > temp.file
rm -r < temp.file
0
 
LVL 11

Expert Comment

by:griessh
ID: 6368233
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
0
 

Author Comment

by:phreakin
ID: 6368686
The OS is HP-UX 10.24
0
 

Expert Comment

by:tryno
ID: 6372439
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.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6814898
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.
http://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
0
 
LVL 11

Expert Comment

by:griessh
ID: 6814953
Since we didn't get any feedback from the asker about the precision needed, I claim that I provided a working solution.

======
Werner
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6940691
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
0
 
LVL 11

Expert Comment

by:griessh
ID: 6940771
Don't feel sorry! My revenge is in CS already :-)

=======
Werner
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question