Recursively remove all empty or almost empty directories

find /i-data/md0/video/ -type d -empty -delete

# print files/directories with size less 1M:
cd /********/Videos/couchpotato-complete
du -sh * | grep -P "\d+K" | awk '{for (i=2; i<NF; i++) printf $i " "; print $NF}' | sort
du -sh * | grep -P "\d+K" | awk '{for (i=2; i<NF; i++) printf $i " "; print $NF}' | sort > movies_to_delete.txt
while read -r file; do rm -rv -- "$file"; done < movies_to_delete.txt
rm -v movies_to_delete.txt

One thought on “Recursively remove all empty or almost empty directories”

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.