Occasionally you get empty directories and need to clear them out, these scripts below will help with that, just be careful what directory you choose.
The scripts below are set to ~/ (current user home directory) but can easily be changed to any directory on your system.
# List empty files find ~/ -depth -empty -type f # List empty directories find ~/ -depth -empty -type d
# Delete empty files find ~/ -depth -empty -type f -delete # Remove .DS_Store and more files before delete empty directories so it actually removes empty directories find ~/ -depth \( -name "Thumbs.db" -o -name "desktop.ini" -o -name "error_log" -o -name ".DS_Store" -o -name "._*" -o -name "SyncToy*.dat" -o -name "Picasa.ini" \) -type f -exec rm -rfv {} \; # Remove empty files in general before delete empty directories find ~/ -depth -empty -type f -exec rm -rfv {} \; # Delete empty directories find ~/ -depth -empty -type d -exec rm -rfv {} \;
# Delete empty files find . -depth -empty -type f -delete # Remove .DS_Store and more files before delete empty directories so it actually removes empty directories find . -depth \( -name "Thumbs.db" -o -name "desktop.ini" -o -name "error_log" -o -name ".DS_Store" -o -name "._*" -o -name "SyncToy*.dat" -o -name "Picasa.ini" \) -type f -exec rm -rfv {} \; # Remove empty files in general before delete empty directories find . -depth -empty -type f -exec rm -rfv {} \; # Delete empty directories #find . -depth -empty -type d -delete find . -depth -empty -type d -exec rm -rfv {} \;
Similarly if you have a file or directory in multiple subdirectories that you need removed you can do
# Delete files - Option 1 find ~/ -depthDocuments/WebSite -name "Thumbs.db" -type f -exec rm -rfv {} \; find ~/ -depthGoogle\ Drive -name "desktop.ini" -type f -exec rm -rfv {} \; # Delete files - Option 2 find . -name "SyncToy*.dat" -print0 | xargs -0 rm -rf # Delete directories that Dreamweaver adds find ~/ -depthDocuments/WebSite -name "_notes" -type d -exec rm -rfv {} \;
Last Updated on January 29, 2024