It's safe to run the previous command as it will only display the list of files that match the search, they will not be deleted or modified, for example a possible output would be. -type f: Limit search results to files.If you need to search for files older than 20 minutes, you would simply use -mmin +20. In our case, we want to search files older than 10 minutes. -mmin +: The mmin option is used to find files/directories with last modified in minutes (replace minutes with the amount of minutes as an integer).You can remove this if you have subdirectories where the search should be executed as well. -maxdepth 1: limiting search to the specific directory given as first argument.-daystart: measure times from the beginning of today.Personally I recommend to use absolute paths, it will prevent possible headaches in the future. your-directory: the absolute or relative directory where the search should be executed. your-directory -daystart -maxdepth 1 -mmin +10 -type f To do this, I simply used the find command: find. Instead of working with the programming language of the project, I decided to simply write a very simple script that does the mentioned algorithm, so I had to research as first, how to find the files that are older than 10 minutes from the current time. In this article, I will share with you a very simple command to search for files older than x minutes from the current time and delete them using bash. This happens basically because we can't afford too much storage and it could become a trouble sooner or later due to the privacy and all the related stuff, so the solution is basically to program a cronjob that runs every 15 minutes, searches the files where 10 minutes have passed since the upload time and delete them, that simple. For the latest project i've been working on ( removeimagebg.io) I had to implement a feature where basically, all of the uploaded files in the server should be deleted where from the date and time of upload, there are 10 minutes difference to the current date and time.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |