Search code examples
linuxredhat

How to make crontab housekeep script to remove files older than 60days in a directory in redhat 7


I have below directory to housekeep :

/interface/P23/FTP/MTSI/arc

/interface/P23/FTP/iMind360/arc

/interface/P23/FTP/ServiceNow/arc

can anyone help me to show some scripts to remove the files older thanenter code here 60days?

i want to keep only new files and housekeep the old files inside those directory.


Solution

  • You can use find command as bellow

    find <Path> -mtime +<NumberOfDay> -exec rm {} \;
    

    -mtime, is used to specify the number of days old that the file is.

    -exec, allows you to pass in a command such as rm. The {} \; at the end is required to end the command.