Delete File 5 Min old in Unix (Bourne Shell)??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete File 5 Min old in Unix (Bourne Shell)??
# 1  
Old 03-10-2009
Delete File 5 Min old in Unix (Bourne Shell)??

Guys,

I am writing a script to delete files 5 min old in Sun Os Unix.

find . -name "*.txt" -mtime +1 -print

I could find an equivalent command to look for files which are 5 min old. i tried -mmin option it didn't work either.

Can any body trow a light on this.


Cheers Smilie
SSmilie
# 2  
Old 03-10-2009
Try this:
find . "*.txt" -type f -mtime +1 -exec del {} \;
# 3  
Old 03-10-2009
Doesn't work either. -mtime +1 calculates the number of day, i am looking for minutes.
# 4  
Old 03-10-2009
Use -mmin , man find
# 5  
Old 03-10-2009
So you need to leave only the files modified/created in the last 5 minutes?

If the files are in the same directory:

Code:
perl -e'(5/1440) < -M and unlink for glob "*"'

But be careful! Backup your data and test the command with print instead of unlink first!


Code:
perl -e'(5/1440) < -M and print for glob "*"'

... and adjust the glob appropriately.

Let me know if you need a recursive solution.

Last edited by radoulov; 03-10-2009 at 05:25 PM.. Reason: corrected, > to < ...
# 6  
Old 03-10-2009
Thanks Radoulov. It worked.

Cheers Smilie
S
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find if file is 45 min old if yes delete

Hello, we have process2(my_pro.sh) which check for the file Pr_rn_Chk (generated by other process1). The process runs every 15 min. if exist Pr_rn_Chk the process will exit. Else it will continue. I want to check if the file Pr_rn_Chk is older than 45 min delete the file. so that 4th run... (3 Replies)
Discussion started by: kumar30213
3 Replies

2. Shell Programming and Scripting

Open a file from within a Bourne shell Script

I am suppose to make a program that cuts the extension off of a file. It uses that .ext to decide which program needs to be used to open the file. This only finds the name of the program from a list of programs I made. My problem is when it has the name of the program it needs to use, how can I... (3 Replies)
Discussion started by: dordrix
3 Replies

3. Shell Programming and Scripting

Shell script: If a file stays in a particular directory more than 30 min send an email

Hi , I am new to shell scripting. i have a requirement say i will receive a file in a directory say /xyz.if that file stays in that directory more than 30 min i need to get a mail to my outlook.this should run for every 20 min in crontab. can anyone help me? (8 Replies)
Discussion started by: muraliinfy04
8 Replies

4. Shell Programming and Scripting

Help required on basic Unix Bourne Shell Script

Howdy People :), I'm a newbie & its my first question here. I've started learning Unix Bourne Shell scripting recently and struggling already :p Can someone PLEASE help me with the following problem. Somehow my script is not working. Display an initial prompt of the form: Welcome to... (1 Reply)
Discussion started by: methopoth
1 Replies

5. Shell Programming and Scripting

How to check the repetition values in a file using bourne shell

Hi all, I have a scenario, like consider a file abc.txt, inside abc.txt, the contents is value1 = aaa, value2 = bbb, value3 = ccc, value1 = ddd. In this situation i need to throw an error for the repeatation of keys like "value1" is repeating twice. how to handle this using bourne... (1 Reply)
Discussion started by: Nandagopal
1 Replies

6. UNIX for Dummies Questions & Answers

How to find whenther given value is in betwwen min and Max in unix shell scripting

Hi I wanted to write a shell script with an if condition Example MinValue=10 MaxValue=30 logvalue = some integer value that script reads from the command line arguement I wanted to check whether log value greater than or equal to10 and less than equal to 30 and proceed with the rest of... (5 Replies)
Discussion started by: pinky
5 Replies

7. UNIX for Dummies Questions & Answers

How do I test for the presence of a file in Bourne Shell

How do I test for the presence of a file in Bourne Shell (3 Replies)
Discussion started by: vins
3 Replies

8. Shell Programming and Scripting

UNix Bourne Shell

i require a utility that identifies all users currently logged into the system. It should create a file called logfile which contains a list of usernames together with a count of how many login sessions they are currently running, for example coc9io : 1 hbh8jd : 3 dg7hy : 1 root : 4 it... (3 Replies)
Discussion started by: peter112
3 Replies

9. UNIX for Dummies Questions & Answers

If file exists (bourne shell)

Im trying to code some logic into a test script to test for the existence of a file before recreating it. Im using the following line to test for this: if -r test.txt; However I get the error message ./testScript.sh: -r: not found Having read through the man pages im still not clear whats... (2 Replies)
Discussion started by: blakmk
2 Replies

10. Shell Programming and Scripting

Read a file and replace a value- Bourne and Korn shell

Hello, I have a file called Delete and within the delete file I have the following statement: delete from employee where employee_id = " " how do I write a script that read from this file and replace: employee_id = " " with employee_id is null Please assist...greatly... (3 Replies)
Discussion started by: kenix
3 Replies
Login or Register to Ask a Question