Skip to content

Instantly share code, notes, and snippets.

@rowwingman
Last active January 5, 2018 09:45
Show Gist options
  • Select an option

  • Save rowwingman/27853f3b842f62f8fde880775c991ec9 to your computer and use it in GitHub Desktop.

Select an option

Save rowwingman/27853f3b842f62f8fde880775c991ec9 to your computer and use it in GitHub Desktop.

https://askubuntu.com/questions/719912/how-to-find-all-empty-files-and-folders-in-a-specific-directory-including-files

Find empty folders: From ~/list folder:

find . -empty -type d for listing empty directories and

find . -empty -type f for listing empty files.

find . -type f -exec bash -c 'if [cat "{}" |wc -w -eq 0 ]; then echo "file - {}";fi' \; -or -empty -exec bash -c "echo dir - {}" \; for listing empty folders and files including whitespaces and empty lines

Find empty folders and remove: find . -empty -type d -exec rmdir {} \;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment