Need help please with creating new Script to remove old .log files

Issues related to applications and software problems
Post Reply
hsalem935
Posts: 6
Joined: 2018/10/18 13:23:42

Need help please with creating new Script to remove old .log files

Post by hsalem935 » 2018/10/18 13:36:22

Hello,

Can you please assist me on how to wrote this scripts to remover 2017 and older log files and just to keep 2018?

I have been doing this manually using .txt file

ls command will show:
-rw-rw-r-- 1 198661 Oct 16 09:01 cm-docsis-testsuite-IPv6.tcl-1539693695.log

in text file I modify entry to:
rm cm-docsis-testsuite-OSS.tcl-1501030190.log
but there are many files like that goes back to 2010

Thank for your help

tunk
Posts: 448
Joined: 2017/02/22 15:08:17

Re: Need help please with creating new Script to remove old .log files

Post by tunk » 2018/10/18 14:41:48

Something like this should delete all log-files older than one year:
find . -maxdepth 1 -name "*.log" -mtime +365 -delete
I haven't actually tried it, so I would first test it on some dummy files, e.g. copy all log-files to another dummy directory.

hsalem935
Posts: 6
Joined: 2018/10/18 13:23:42

Re: Need help please with creating new Script to remove old .log files

Post by hsalem935 » 2018/10/18 16:26:37

Thank you very much for the quick response, I will sure try it and follow your advice and backup the file to a different Directory. :D

Post Reply