Score:6

To delete the directories using find command

pg flag

I am using the Linux command to delete the directories from my server.

find . ! -name . -type d -mtime +30 -print -delete

But the directories are not deleting. Attached the image , please refer. I am using prune depth rm -rf folders are deleting. But there is a performance / time taking process. But instead of that can i use the -delete command right.

find command results

Varun K M avatar
pg flag
@guiverc -- I have corrected my tags. Without rm -rf , cant we use -delete command ?
karel avatar
sa flag
Does this answer your question? [Find folders and delete contents](https://askubuntu.com/questions/1119873/find-folders-and-delete-contents)
Raffa avatar
jp flag
Your directories appear to not be empty ... `find`'s action `-delete` only deletes empty directories ... You can use e.g. `-exec rm -r {} +` instead of `-delete` to force deleting non-empty directories with minimal performance penalty because of `+` to process multiple arguments at once instead of `\;`... Be careful though.
Varun K M avatar
pg flag
@Raffa , so -delete is used only to delete empty directories. It wont help to delete the big size directories.
Raffa avatar
jp flag
@VarunKM Yes, it acts on directories like `rmdir` and only removes empty directories ... Also `-mtime +30` will exclude even empty directories modified less than 30 days.
Score:4
jp flag

find's action -delete will act on directories similar to rmdir i.e. will only remove empty directories and error otherwise ... So you might want to use instead something like:

find . ! -name . -type d -mtime +30 -print -exec rm -r {} + -depth

to delete non-empty(in addition to empty) directories recursively.

Varun K M avatar
pg flag
Thanks for your response. Actually i am using this command ,previously. But only problem is with this command it taking much time to delete the records. need to improvise the command in the sense of server performance and quicker. Thats why i thought of delete command, but i understood it is used for only empty directories. Note: I am deleting around some millions of record and storage in Giga bytes.
I sit in a Tesla and translated this thread with Ai:

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.