Review your favorite Linux distribution.
Go Back > Forums > Other *NIX Forums > AIX
User Name
AIX This forum is for the discussion of IBM AIX.
eserver and other IBM related questions are also on topic.


  Search this Thread
Old 10-31-2008, 08:10 AM   #1
LQ Newbie
Registered: Oct 2008
Posts: 2

Rep: Reputation: 0
Question 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.
Old 10-31-2008, 02:53 PM   #2
Registered: Jun 2008
Posts: 235

Rep: Reputation: 47

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.

Old 11-04-2008, 04:54 AM   #3
LQ Newbie
Registered: Oct 2008
Posts: 2

Original Poster
Rep: Reputation: 0

Bingo! It worked. I used while loop containing find + grep command.
Thanks for your reply.
Old 12-04-2008, 08:24 AM   #4
LQ Newbie
Registered: Dec 2008
Posts: 1

Rep: Reputation: 0

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



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using find and rm command to delete files over x days old 200mg Linux - Newbie 16 09-03-2008 07:41 PM
Script help - delete files older than 45 days but exclude the system files jojothedogboy Linux - Software 3 06-13-2008 04:43 PM
How to Find and remove 7 days before modified/created files neel.gurjar Linux - Software 2 05-14-2008 09:17 PM
script to auto delete files older than X days nocnoc Programming 17 12-06-2006 09:30 AM
help with a script that deletes files more than X days old BrianK Linux - General 5 06-14-2004 10:05 PM > Forums > Other *NIX Forums > AIX

All times are GMT -5. The time now is 08:52 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration