Operating System - Linux
1753483 Members
4507 Online
108794 Solutions
New Discussion юеВ

Re: script for remove file time basis

 
SOLVED
Go to solution
Francesco_13
Regular Advisor

script for remove file time basis

Hi,
I need a script in Ksh for remove only the old files; for example the files with more then 4 weeks.
Thank
7 REPLIES 7
Pete Randall
Outstanding Contributor

Re: script for remove file time basis

find /dirname -type f -mtime +28 -exec rm {} \;


Pete

Pete
Robert-Jan Goossens_1
Honored Contributor
Solution

Re: script for remove file time basis

Hi,

locate the files
# find /dir -mtime +28 -exec ls -l {} \;

# find /dir -mtime +28 -exec rm {} \;
remove the files.

Hope this helps,
Robert-Jan
RAC_1
Honored Contributor

Re: script for remove file time basis

Check man page of find. -mtime option.

find /dir_wher_files_reside -mtime +28 -exec rm {} \;

There is no substitute to HARDWORK
Francesco_13
Regular Advisor

Re: script for remove file time basis

Ok...Thank
Ciao a tutti!
I.Delic
Super Advisor

Re: script for remove file time basis

Hi francesco,

For the first time i should use option -OK

find . -mtime +28 -ok rm {} ';'

Then you can see witch file you just removed.

Succes

Idriz
Jordan Bean
Honored Contributor

Re: script for remove file time basis

HP's find has a builtin xargs feature to avoid spawning rm for each file:

find /dir -type f -mtime +28 -exec rm -f \+

The result is similar to:

find /dir -type f -mtime +28 | xargs rm -f

I don't believe -ok works this way, but you can acheive that in this way:

find /dir -type f -mtime +28 | xargs rm -i

Francesco_13
Regular Advisor

Re: script for remove file time basis

thanks