how to delete the files which are the 30 min older...?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to delete the files which are the 30 min older...?
# 1  
Old 06-13-2008
how to delete the files which are the 30 min older...?

Hi all,

i have a simple question that i want to find out the 30 minutes older files and delete those files from the particular location(Folder)

Generally for this purpose used to retreive the files with "atime" command

For example: find and delete the 2 days older log files use this below command

find $HOME/Log -type f -name "*.log" -atime+2 -exec {} \;

But how can use for 30 min older files...?

Suggession are apprciated.

Thanks and Regards,
MPS
# 2  
Old 06-13-2008
Use *min for minutes.
Code:
find $HOME/Log -type f -name "*.log" -amin +30 -exec ls {} \;

# 3  
Old 06-13-2008
If the OP is on Linux or has GNU find -amin works

Otherwise try:
Code:
#!/bin/ksh
# filetimes
filetime()
{
    perl  -e '
          $mtime = (stat $ARGV[0])[9];
          print $mtime
         ' $1
}
now=$(date +%s)
limit=$(( $now - 1800 ))  # one half hour ago.

find /path/to/files -type f |\
while read filename 
do
	dt=$(filetime  $filename)
	if [[ $dt -lt $limit ]] ; then
   		rm -f $filename  # delete ALL files older then 30 minutes
   	fi
done

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to delete all the files older than a date?

Hi, I need a command for deleting all the compress files *.Z that are older than the current date - 5 days. Basically I have a directory where daily I meet some back up files and I want to remove automatically the ones 5 days (or more) older than the current date. How can I write a 'rm' command... (1 Reply)
Discussion started by: Francy
1 Replies

2. Shell Programming and Scripting

Delete files older than X days.

Hi All, I am using below code to delete files older than 2 days. In case if there are no files, I should log an error saying no files to delete. Please let me know, How I can achive this. find /path/*.xml -mtime +2 Thanks and Regards Nagaraja. (3 Replies)
Discussion started by: Nagaraja Akkiva
3 Replies

3. Shell Programming and Scripting

To delete files older than 24 hrs

I have to retain only 1 day files in my system an I have to delete all the other files which are older than 24 hrs. Please let me know the option I have to give in the find -mtime command. (3 Replies)
Discussion started by: rajesh8s
3 Replies

4. Shell Programming and Scripting

Delete files older than today

is it -mtime +1 as i need all files older than today to be deleted (6 Replies)
Discussion started by: dinjo_jo
6 Replies

5. Solaris

Delete files older than 30 days

Hi all, I want to delete log files with extension .log which are older than 30 days. How to delete those files? Operating system -- Sun solaris 10 Your input is highly appreciated. Thanks in advance. Regards, Williams (2 Replies)
Discussion started by: William1482
2 Replies

6. Shell Programming and Scripting

delete files more than 15 days older

i have to delete files which are older than 15 days or more except the ones in the directory Current and also *.sh files i have found the command for files 15 days or more older find . -type f -mtime +15 -exec ls -ltr {} \; but how to implement the logic to avoid directory Current and also... (3 Replies)
Discussion started by: ali560045
3 Replies

7. UNIX for Dummies Questions & Answers

Delete files older than 30 days

This is driving me crazy. How can I delete files in a specifc directory that are over 30 days old? Thanks in advance. (3 Replies)
Discussion started by: tlphillips
3 Replies

8. UNIX for Dummies Questions & Answers

How can I delete files older than 7 days?

I will like to write a script that delete all files that are older than 7 days in a directory and it's subdirectories. Can any one help me out witht the magic command or script? Thanks in advance, Odogboly98:confused: (3 Replies)
Discussion started by: odogbolu98
3 Replies

9. UNIX for Dummies Questions & Answers

delete files older than 7 days

can anyone tell me how I would write a script in ksh on AIX that will delete files in a directory older than 7 days? (1 Reply)
Discussion started by: lesstjm
1 Replies
Login or Register to Ask a Question