command to delete empty folders on linux

Sometime we need to find remove only those folders which are empty. (Doesn’t contains any file or folder) .  rmdir is command which will delete folder only if it is empty.

find . -type d -exec rmdir {} \;
This command will find all files with type d (type d means all files those are directories) in present folder. Then execute rmdir for all directories but since rmdir will remove only empty folder and for other it will throw error.

Leave a Reply

Your email address will not be published. Required fields are marked *