Linux Shell script to find empty directories under a parent directory

| | 1 min read

Here is a script to help you find empty directories located under a specified parent-folder. The file folders.txt contains the list of folders that are to be passed as input to the script. The script will now check all the folders mentioned in the file folders.txt, and give the list of folders that are empty. The output can either be seen at the terminal or it can be passed to a file via a redirector.

Here is the code for the same:

#!/bin/bash
# Script to find empty directories 
# Read the name of folders from the folders.txt file
#   path to the folder
#find . -type d -empty will find all empty directories

path=/path/to/the/parent/folder

while read folder
do
  echo "$folder"
  cd $path/$folder
  empty=`find . -type d -empty`
  echo -e "$empty" 
done < folders.txt