User Tools

Site Tools


linux:find:find_empty_directories

Linux - Find - Find Empty Directories

find ./ -type d -empty

This command will find all empty directories in the current directory with sub-directories and then print the full pathname for each empty directory to the screen.

  • ./ means start searching from the current directory. If you want to find files from another directory then replace the ./ with the path to needed directory. For example, to search everything under the system log directory you need to replace ./ with /var/log.
  • -type d flag is specifies to find only directories.
  • -empty flag is specifies to find empty directories.

Find and then delete all empty directories

To find and then delete all empty directories, use:

find ./ -depth -type d -empty -exec rmdir {} \;

or

find ./ -type d -empty -delete

NOTE: The -delete option is the best choice when it is supported by the find you are using.

linux/find/find_empty_directories.txt · Last modified: 2020/07/15 10:30 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki