There are some log files created after a certain amount of time with the time stamp.
/mylog/path
Log_file_2018-07-19-22-55-31Z.tgz
Log_file_2018-07-20-01-29-11Z.tgz
Log_file_2018-07-20-10-36-49Z.tgz
Log_file_2018-07-21-18-26-36Z.tgz
I need to delete older logs based on date. For example, I want only last 5 days logs and older logs should be deleted. Num of log files created daily varies. How to achieve this?
You can do with mtime
(modified time) in find
command.
find /mylog/path -mindepth 1 -mtime +5 -delete
-mindepth 1
means process all files except the command line arguments.-mtime +5
will check for the files modified 5 days ago.-delete
will delete이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다