List of files in c:\temp Now that you know the files to remove, you can create a script to only delete files that are older than a specific number of days in this case, older than 14 days. Note: Do ensure your server time is set correctly via date - setup timezone/ntp correctly. As you can see in the screenshot below, there are files that are 15 days old, 7 days old, and 0 days old. Note: to test the code, just use -print instead of -print -delete. 247 specifying time relative to, 246247 Dates portion, Mac OS X. calculates the elapsed time for the backup operation. deleting old files, 259 overview, 258 formats for, 242244 forming on fly.log files older than 7 days are deleted ( assuming this is for a backup log).maxdepth 1 ensures you dont enter subfolders Before you resell, recycle, or donate an old laptop, learn how to wipe a computer clean and protect your personal data with this Consumer Reports guide.find looks for *.txt files only in the log folder.Just spicing up the shell script above to delete older files but with logging and calculation of elapsed time #!/bin/bashįind $path -maxdepth 1 -name '*.txt' -type f -mtime +$days -print -delete > $logĮcho 'Backup:: Script Start - $(date +%Y%m%d_%H%M)' > $log