So, I have a folder with alot of files, they are generated by second and need to be kept in I only can delete them after 90 days, so as you may guess, I would generate tons of files and then after the 90 days I'm able to delete those files that is older than 90 days. But, I'm stuck in the part where I search for those files, since I have alot, the system complains that the list is too large and thus I can't remove them.

What is the best solution so I can pass this? The file names are in timestamp mode, so I could start by it, but I want to make sure all files are deleted after some time....

I have tried these methods

rm -rf *
find /path/to/files/ -type f -name '*.ts' -mtime +90 -exec rm {} \; 

I have also managed to create a script to delete by filename, but with this method I have no guarantee that all the files are deleted.

  • What methods have you tried that the system complains about? – jesse_b Jan 3 '18 at 12:24
  • Since I'm still developing this, yesterday I generated about 5 days of files and want to erase them, I just did a rm -rf * and the system yelled at me. – Lucas César Jan 3 '18 at 12:25
  • 1
    The problem is not only deleting them....think ahead, and create a directory structure YEAR/MONTH/DATE/HOUR automatically, it will be easier to manage. – Rui F Ribeiro Jan 3 '18 at 12:25
  • 2
    Please don't ever do rm -rf *. You should always be as specific as possible when removing files with globbing. rm -- ./* would be better for you, no need for -r as you want to remove files not directories, and you should only use -f if you have to. – jesse_b Jan 3 '18 at 12:30
  • 1
    When you say several methods weren't effective, please provide more detail. Edit your question to include exactly the command you issued and any error messages or other relevant output produced. – user4556274 Jan 3 '18 at 12:33

If the files are not modified after initial creation, you could delete if they have not been modified in over 90 days:

find /path/to/folder -mtime +90 -delete


find /path/to/folder -mtime +90 -exec rm {} +

(for versions of find which do not support the -delete action).

As a matter of safety, you should use a non-destructive version of this command first and ensure it will delete exactly what you want deleted, especially if you intend to automate this action via cron or similar, e.g.:

find /path/to/folder -mtime +90 -print

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.