Hi,
I have to find the files older than 10 minutes and remove those files as well as redirect the file names into a log file.
i am using sun OS and my unix is not GNU and also not having perl.
Could any one suggest me the way to approach. It would be great if script is provided.
Also following commands are not supporting.
date -v
find . -type f -mmin -10
(find: bad option -mmin)
I don't use SunOS, but perhaps you can accomplish your goal using the following POSIX functionality:
1) Use touch to create a file whose mtime is 10 minutes in the past.
2) Use find's -newer (negated with !) to match files that are older than the file which was touched.
# cat agenew.c
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char* argv[]) {
int modift;struct stat* buf;
buf=(struct stat *)malloc(sizeof (struct stat));
if (stat(argv[1],buf) != 0) {
perror(argv[1]);
return EXIT_FAILURE;}
(int) modift =difftime(time(NULL),buf->st_mtime);
printf("%d\n",modift);}
# gcc agenew.c -o agenew ; for file in `find . -type f `; do agemin=$(echo "`./agenew $file`/60"|bc)
if [ $agemin -gt 10 ] ; then echo "$file's age is $agemin min" ; fi; done
Thanks for the solutions. I would like to go with following solution.
(1) Use touch to create a file whose mtime is 10 minutes in the past.
(2) Use find's -newer (negated with !) to match files that are older than the file which was touched.
Here, how to create a file dynamically whose time is 10 minutes past by comparing with current time.