cancel
Showing results for 
Search instead for 
Did you mean: 
Trevor
Commander Commander
Commander
  • 231 Views

Remove Empty Directories

Jump to solution

I want to remove all directories (and subdirectories) that are empty - in the current directory.
One command I know that will accomplish this is:

         $  find . -type d -empty -exec rmdir -v {} \; 2>/dev/null

 

Is there any other single command - NOT script, or chaining of commands
via pipes -  that that can accomplish this?

If there isn't any other single command to accomplish this, I'll entertain other
methods.  However, I'm primarily interested in 'siingle' commands!!!!

 

Trevor "Red Hat Evangelist" Chandler
Labels (3)
1 Solution

Accepted Solutions
Chetan_Tiwary_
Community Manager
Community Manager
  • 128 Views

@Trevor Your command also contains a loop or a piping like thing as "-exec" .

Best one liner is : 

find /path/ -type d -empty -delete

 https://man7.org/linux/man-pages/man1/find.1.html 

Chetan_Tiwary__0-1765828000266.png

 

View solution in original post

2 Replies
Chetan_Tiwary_
Community Manager
Community Manager
  • 129 Views

@Trevor Your command also contains a loop or a piping like thing as "-exec" .

Best one liner is : 

find /path/ -type d -empty -delete

 https://man7.org/linux/man-pages/man1/find.1.html 

Chetan_Tiwary__0-1765828000266.png

 

Trevor
Commander Commander
Commander
  • 78 Views

Nothing like 2 sets of eyes - especially when one of those sets is
guaranteed to detect flaws, and elevate the solution!!!

Thanks Chetan for another contribution to the elevation of my
knowledgebase!!!

Trevor "Red Hat Evangelist" Chandler
Join the discussion
You must log in to join this conversation.