-   AIX (
-   -   Script: purge files more than N days old. Need Non Recursive Find (

explore.s 10-31-2008 07:10 AM

Script: purge files more than N days old. Need Non Recursive Find
source file contains paths of the directories from which files need to be purged (older than N days)


From above file I read each path line by line. For each line I need to remove the files under that directory one by one.

I am using foll. command on AIX.

find $purge_dir_path -type f -mtime N -print | xargs rm -f

Find does a recursive search & traverses through all the subdirectories.
I am looking to restrict the search only to the directory specified by $purge_dir_path excluding its subdirectories.

I tried -maxdepth option. Even if the man find lists -maxdepth, the command doesn't run.
bash-2.05b$ find . -type f -maxdepth 0 -mtime +30 -print
find: bad option -maxdepth

I tried for -prune option, but since subdirectory names are not fixed for each directory to be purged, it seems to be ruled out.

I have even tried -xdev option. It doesn't work either.

Please help.

jan61 10-31-2008 01:53 PM


I think you have no chance to do it in a single find in AIX, but you can combine a find with a grep:

find $purge_dir_path -type f -mtime +100 -print | grep -vE "^$purge_dir_path/.+/" | xargs rm
The grep filters out all pathnames containing a subdirectory part below $purge_dir_path.


explore.s 11-04-2008 03:54 AM

Bingo! It worked. I used while loop containing find + grep command.
Thanks for your reply.

neilsie 12-04-2008 07:24 AM


is it possible you can send me a copy of this script?


All times are GMT -5. The time now is 12:34 PM.