![]() I’m new to cron, so I’d really appreciate someone pointing out where I’ve gone wrong, or how to diagnose it if not obvious. I can see the job is running, but the files still exist in the folder. txt files in a folder that are older than 7 days. ![]() ![]() Or ! -type d to consider all types of files except directories. Can a cron job delete all.txt files I have a cron job that runs at midnight to delete all. To delete only regular files (and exclude all other types of files including fifos, sockets, directories, symlinks.), add -type f before -delete. ![]() So if an old file is removed from a directory, that directory won't be removed even if it was over an hour old at the time find was started.Īlso note that for files of type symlink, it's the age of the symlink itself, not that of the target of the symlink that is being considered. Also note that removing a file from a directory does update the last modification time of that directory, and -delete implies -depth meaning that files are processed before the directory where they're found in. That deletes all files regardless of their type, though note that it won't delete files of type directory if they're not empty. So would not select the files whose age is in-between 60 and 61 minutes. Note that -mmin +60 would select the files whose age in minutes rounded up to the next integer is strictly greater than 60. Here using the -mmin and -delete extensions of GNU find, as found on Ubuntu and other GNU-based systems. To delete the files whose name starts with master-stdout.log and that have not been modified in the last hour, recursively under /root/logs/: LC_ALL=C find /root/logs/ -name 'master-stdout.log*' -mmin +59 -delete
0 Comments
Leave a Reply. |