Linux Shell – Script to Delete Files Older Than 30 Days

linuxredhatshellsyslog

Shell script should not delete any files under* root dir*. My* path will be like
/export/home/ftp/ …

I did some research and figured out the way for finding and deleting the files older than 30 days from a specific path, using find and exec commands.

*find /export/home/ftp/ -type f -mtime +30 -exec rm -f {} \;

But according to the requirement I want to delete console.log and server.log only from that directory and exclude the remaining files.

Please help me out in this issue.

Best Answer

Assuming you really need to be using find in order to recurse through subdirectories:

find /export/home/ftp \( -name console.log -or -name server.log \) -mtime +30 -exec rm -f {} +