Delete empty directories recursively
delete empty directories linux | remove empty folders recursively | clean up empty subdirectories | find | cleanup | deleteWarning, destructive. This command deletes, overwrites or changes data in a way that cannot easily be undone. Check every placeholder carefully and make a backup first.
find /var/www/vhosts/example.com/httpdocs -mindepth 1 -type d -empty -print -deleteDeletes every empty directory below the path, while -mindepth 1 keeps the starting path itself. Since -delete works from the inside out, folders that only contained empty subfolders are removed too. Files are not touched.
Note: Applications sometimes expect empty folders (upload, cache or lock directories) and fail without them. Check the list with find ... -type d -empty first.
Also searched as
- delete empty directories linux
- remove empty folders recursively
- clean up empty subdirectories