Score:0

Slowly delete lots of subdirectories without impacting the server's performance

us flag

I need to clean a directory which contains millions of subdirectories. I want to delete all subfolders that are older than 365 days. I tried this command:

sudo nice -n 19 ionice -c 3 find . -type d -mtime +365 -exec rm -rf '{}' +

However, while this command runs, everything else on the machine gets very unresponsive.

Is there another way how to throttle the deletion of millions of subdirectories?

I run it on Ubuntu 20 with 256GB of memory.

cn flag
The rm is not the problem. It is the find.
in flag
You may want to look at using something like [tmpreaper](http://manpages.ubuntu.com/manpages/focal/man8/tmpreaper.8.html) and starting with a very high number of days, then slowly work your way down to 365. [This blog post](https://www.thegeekstuff.com/2013/10/tmpreaper-examples/) outlines some of the ways you can use the tool.
us flag
thanks @matigo, so you suggest to use something like `sudo nice -n 19 ionice -c 3 tmpreaper /home/mydirectory` ?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.