Need to remove files older than 30 days except directories

Hi,

I need to remove files (*.trc) which are older than 30 days from one location.

My problem is there I do not want to visit any of the directories at that location. I want to search files at that particular location only (need to skip directorys at that location). maxdepth option is there in LINUX find but its not there in solaris.

How can I do that?

Thanks in advance.

Regards,
Malay Maru

Hi,

Try the following:

find . -name "*.trc"  -mtime +30 -exec rm -rf {} \;

Regards,
Nir

But it will remove the tracefiles which resides under directoris at that location.

I want to skip this directories.

Malay

find . \( -type d ! -name . -prune \) -o  -mtime +30 -exec rm -rf {} \;

Jean-Pierre.

Hello ,

In addition to the problem , if i want to find and remove the files made in last 5 mins then what will be the command as , i have searched for many coomand but all depend upon days not time!!!

KRegards,
Aparna

A solution is to use the -newer expression of the find command.

  1. Compute current date/time minus 5 mn
    The Perderabo's datecalc and Simple date and time calculation in BASH may help you.
  2. Create a timestamp file with access and modification times equal to the computed date/time :
    touch -t [[CC]YY]MMDDhhmm[.SS] timestamp_file
  3. Find files newer that the timestamp file.
    find . -type f -newer timestamp_file -exec rm -f {} \;

Jean-Pierre.

Thanks a lot for the solution

KRegards,
Aparna