LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   AIX (http://www.linuxquestions.org/questions/aix-43/)
-   -   Script: purge files more than N days old. Need Non Recursive Find (http://www.linuxquestions.org/questions/aix-43/script-purge-files-more-than-n-days-old-need-non-recursive-find-680253/)

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)

/home/xyz
/home/abc
/home/def

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

Moin,

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

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.

Jan

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

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

neilsie 12-04-2008 07:24 AM

hello,

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

cheers.


All times are GMT -5. The time now is 04:34 AM.