![]() Some finds also have a -execdir that mitigates against those vulnerabilities. So don't use it on directories that are writeable by others. A POSIX compatible approach would be: find /a/b/c/1 /a/b/c/2 -type f -mtime +3 #-exec rm + has race condition vulnerabilities which -delete (where available) doesn't have. UpdateĪs noted below, the -delete option for find isn't very portable. Provided of course that you do not need a more specific schedule and that these directories exist on your distro. Check whether the path exists or not using the os.path.exists (path) module. ![]() ![]() Convert the number of days into seconds using time.time () method. mtime +30 -print The above command will find and display. To have it run by cron, I would probably just create an executable script (add a shebang - #!bin/sh to the top line of the file and make executable with chmod a+x), then put it in an appropriate cron directory like /etc/cron.daily or /etc/cron.weekly. Follow the below steps to write code for the deletion files/folders based on the number of days. Now we can try to delete all files on /testscript running the command: 1. First, let us find out the files older than X days, for example 30 days. ![]() Remove the # before the -delete once you are sure that it is finding the files you want to remove. This is easy enough (although note that this goes by a modification time more than 3 days ago since a creation time is only available on certain filesystems with special tools): find /a/b/c/1 /a/b/c/2 -type f -mtime +3 #-delete
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |