files older than 10 minutes

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)

Thanks.

Never seen a Sun OS without Perl ...

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.

Regards,
Alister

firstly you are using sun os but which one 8-9-10-11 or older ?

1-)if you dont have gnu findutils then you must use (have to) use perl with find the modif minutes.
2-)or might be install gnu-coreutils to use stat command for get file times.
ftp://ftp.sunfreeware.com/pub/freeware/sparc/10/coreutils-8.11-sol10-sparc-local.gz
ftp://ftp.sunfreeware.com/pub/freeware/SOURCES/coreutils-8.11.tar.gz
3-)or you have to use method of @alister , but everytime..
4-)or can write a c/perl program..

time.h -->
struct timeval {
        time_t          tv_sec;         /* seconds */
        suseconds_t     tv_usec;        /* and microseconds */
};
stat.h -->
struct stat {
        dev_t           st_dev;
        ino_t           st_ino;
        mode_t          st_mode;
        nlink_t         st_nlink;
        uid_t           st_uid;
        gid_t           st_gid;
        dev_t           st_rdev;
        off_t           st_size;
        timestruc_t     st_atim;
        timestruc_t     st_mtim;
        timestruc_t     st_ctim;
        blksize_t       st_blksize;
        blkcnt_t        st_blocks;
        char            st_fstype[_ST_FSTYPSZ];
};
 
#define st_mtime        st_mtim.tv_sec
time_impl.h -->
typedef struct timespec timestruc_t;    /* definition per SVr4 */

maybe you can this.

# 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

regards
ygemici

Its always a good idea to do a

man find

and see what options your find allows you to do. The man files are always very helpful in these regards.

Hi, I have to find files older than 10 minutes and have to remove those files as well as to redirect file names into log file.

I am using SUNOS unix and it is not having GNU version.
Also below commands are not supporting.

date -v
find . -type f -mtime +10

could any one help me for this requirement.

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.

Got perl?

#!/bin/sh

#----subtract 10 minutes (600 seconds) from time
STAMP=$(perl -e '($ss, $mm, $hh, $DD, $MM, $YY) = localtime(time() - 600);
printf "%04d%02d%02d%02d%02d", $YY + 1900, $MM + 1, $DD, $hh, $mm')

#----create an empty file with a timestamp of 10 minutes ago
touch -t $STAMP /tmp/flagfile

#----find older files
find /start/dir -type f ! -newer /tmp/flagfile -print |\
while read FILE
do
  : something with $FILE
done

Threads merged.