Operating System - HP-UX
1833471 Members
2679 Online
110052 Solutions
New Discussion

remove files by filenames and date

 
Nitin Nigam
Occasional Advisor

remove files by filenames and date

Hi

I want to delete the files by filename and date.
if I use
"find /home/test/gr* -mtime +5 | xagrs rm"
it works fine but the problem is I have nearly 30 different files and there is possibility that new files can be added to the directory.
What I want is the script that will look for the filenames and if they are 5 days old delete them.
At the same time I want to delete some files on the same directory after 10 days.
and if new files are added then delete them after 15 days.
thanks
3 REPLIES 3
twang
Honored Contributor

Re: remove files by filenames and date

How about this,
find /home/test/gr* -name -mtime +5 -exec rm {} \;
find /home/test/gr* -mtime +10 -exec rm {} \;

Rajeev  Shukla
Honored Contributor

Re: remove files by filenames and date

Hi,
Have a look at the man pages of "find" you'll see many more options you can use with it to fine tune you'r deletion.
like

find -type f -name -mtime +5 -exec rm {} \;

same for 10 and 15 days

Bhuvaneswari Selvaraj
Valued Contributor

Re: remove files by filenames and date

Hi,
Can you please elaborate the question? What do you want to do?

You know that in the command that you had given
find /home/test/gr* -mtime +5 | xagrs rm"

the mtime can be changed to 5 or 10 or 15 or whatever you want and executing the commands in sequence will delete the files based on mtime..

Is that what you want to do? or you want to accomplish all these in a single command? or do u want to do something alltogether different?