Here is how to find empty files in the current directory:
find . -maxdepth 1 -type f -empty
-type f --> filter only files
-empty --> filter only empty
-maxdepth --> how many levels of sub directories to search?
To find all empty files and folder
find . -empty
To delete the empty files:
find . -maxdepth 1 -type f -empty -delete
Use it carefully. It will delete all the empty files like __init__.py
files also.
To delete files:
find . -maxdepth 1 -type f -name *.py -exec rm -rf '{}' '+'
Use it carefully, it will delete all python files, even if they are not empty.
Top comments (0)