Unix Linux find and delete empty folders and files

Never Code Alone
1 min readJun 29, 2023

Finding and deleting empty folders and files with Unix is a task in the cleanup of project directories. These are basically not even recorded in Git, but anyway they lead to confusion and are also unnecessary. Here a Linux command is necessary, which can be used recursively. With the following commands one can find and also remove empty directories and files in Linux file structures. For this work it is of course advisable to have a fullbackup of the system. It is also possible that applications insist on certain folders or files, even if they are simply empty.

Unix Linux find empty folder in current directory

find . -type d -empty

Unix Linux find empty directories in current directory and remove them automatically

find . -type d -empty -exec rmdir {} \;

Unix Linux find empty files in current directory

find . -type f -empty

Unix Linux Number of empty files in current directories and subdirectories

find . -type f -empty | wc -l

Unix Linux How many non-empty files are in the current directory and its subdirectories

find . -type f -not -empty | wc -l

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Never Code Alone
Never Code Alone

Written by Never Code Alone

PHP Training und Automatisiertes Website Testing

No responses yet

Write a response