↑ ↓ select, Enter open, Esc close

Delete empty directories recursively

Adjust the values, the command updates live
user@server
find /var/www/vhosts/example.com/httpdocs -mindepth 1 -type d -empty -print -delete

Deletes 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

Related one-liners

All in Filesystem

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.