1827324 Members
4453 Online
109962 Solutions
New Discussion

Creating a script file.

 
SOLVED
Go to solution
ckchai
Frequent Advisor

Creating a script file.

Hi,

I need to creating a script file to delete files inside a folder (ArchiveLog), which maintain the thrahold for 14days.

Please help, I would rewards points for those who help. Thank very much.
6 REPLIES 6
Michael Tully
Honored Contributor
Solution

Re: Creating a script file.

Assuming your filesystem mount point name is /ArchiveLog then this should to the trick. You could also automate this by placing it within cron.

find /ArchiveLog -mtime 14 -print -exec rm {} \;
Anyone for a Mutiny ?
Indira Aramandla
Honored Contributor

Re: Creating a script file.

Hi,

You can list the files to check them as
find /path_name -name "*log*" -mtime +14 -exec ll {} \;

And to delete them

find /path_name -name "*log*" -mtime +14 -exec rm {} \;
Never give up, Keep Trying
Sanjay Kumar Suri
Honored Contributor

Re: Creating a script file.

Deleting is fine.

I hope you have backup policy for taking online/offline backups and the backup of the archive files so deleted.

Archive files will be needed in case of any complete/point-in-time recovery.

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Muthukumar_5
Honored Contributor

Re: Creating a script file.


You can do it as,

find // -name "*" -mtime 14 -exec ll {} \; -exec rm -i {} \;

Which gives the full file informations and as well as user input y / n to delete files too.

Regards
Muthu
Easy to suggest when don't know about the problem!
Saravanan_11
Occasional Advisor

Re: Creating a script file.

find -name "*" -type f -mtime 14 -exec rm -i {} \;

It will delete only the files { thru -type f option }residing in the specified directory which are havg threshold as 14 days with user confirmation for deletion.

ckchai
Frequent Advisor

Re: Creating a script file.

thanks you very much.
Have a nice day.