Find Empty Files in Linux: find, du, and Safe Checks
To find empty files in Linux, use find with -type f -empty; it checks for regular files whose size is zero bytes. For example, find . -type f -empty lists empty files under the current directory, including subdirectories.
What Linux Means by an Empty File
For find, an empty regular file has a size of exactly zero bytes. It may have a name and permissions and still contain no data. A file containing a newline, a space, or any other byte is not empty, even if a text editor displays a blank-looking page.
Directories are not regular files, so -type f excludes them. This distinction matters because a directory that appears empty is a different thing: use find . -type d -empty to find empty directories. A symbolic link to a zero-byte file is also not itself a regular file for this test; by default, find does not follow symbolic links when traversing.
The Basic find Command
Run this from the directory you want to search:
find . -type f -empty
The dot means “start here.” Replace it with a path, such as /var/log or ~/Documents, to search elsewhere. To search only the current directory and not descend into subdirectories, add -maxdepth 1:
find . -maxdepth 1 -type f -empty
To search the whole filesystem, an administrator can start at /, but permission-denied messages are normal for areas the account cannot read. Redirecting error messages can make the output easier to scan:
find / -type f -empty 2>/dev/null
This hides diagnostic messages; it does not grant access or make the search complete. Use a suitable starting directory when possible, since searching all of / can take longer and may traverse mounted filesystems.
Useful Variations and Output
Use -print when you want to make the output action explicit; it is the default action when no other action is given:
find ~/Downloads -type f -empty -print
For filenames containing spaces, tabs, or newlines, avoid parsing a plain newline-separated list in a script. Use NUL-delimited output instead:
find . -type f -empty -print0
For example, this safely passes matching paths to a command that understands NUL-separated input:
find . -type f -empty -print0 | xargs -0 -r ls -l
-print0 and xargs -0 are available in GNU and many other common Linux environments. If portability to less common Unix systems matters, check the local command documentation.
To inspect rather than merely list matches, use -ls:
find . -type f -empty -ls
This shows details such as permissions, ownership, and timestamps. Be aware that a file can change between the search and any later action, especially in active directories.
Other Ways to Check for Zero-Byte Files
The find predicate is usually the clearest recursive method, but other tools help with different needs:
stat filenamereports metadata for one file, including its size. The exact output format varies by system.ls -ldisplays file sizes in a directory. Look for a size of0, but remember that ordinary output does not recursively search subdirectories.du -areports disk usage for files and directories, but it is not the best test for logical file size. Filesystem allocation, sparse files, and display rounding can make disk usage differ from the byte length.
A zero-byte file may still use some filesystem metadata or allocation, while a sparse file can have a large apparent size but use little disk space. These are separate concepts: find -empty tests whether the file’s logical size is zero, not how much storage the filesystem has allocated to it.
Choosing a Search Scope and Handling Permissions
Choose the narrowest starting path that answers the question. A search of a project directory is faster and less noisy than a search of the entire machine. To limit traversal depth, use -maxdepth N where supported; GNU find evaluates this option relative to the starting point.
Files may be missed if the account cannot traverse a parent directory or read directory entries. Running with elevated privileges can expose more of the filesystem, but it also increases the consequences of mistakes. For a read-only inventory, first run the search as your normal user and consider whether broader access is genuinely needed.
Do not assume that every zero-byte file is useless. Programs may intentionally create empty placeholders, lock-related files, markers, or files that will be populated later. A search is an inventory, not a diagnosis.
Deleting Matches Safely
If your goal is cleanup, review the matches before removing anything. First save or inspect the list:
find ./target -type f -empty -print
After confirming that the target path and results are correct, -delete removes matching files:
find ./target -type f -empty -delete
Keep the starting path specific and retain -type f. Do not casually replace it with a broad expression or run deletion from /. If you need an interactive check for each match, GNU find supports -ok, which prompts before running a command:
find ./target -type f -empty -ok rm -- {} \;
Interactive prompts reduce the chance of removing an unintended match, but they do not replace checking the search scope. Back up important data and consider how applications use the files before deleting them.
Frequently Asked Questions
How do I find empty files recursively?
Run find . -type f -empty from the directory to search. find descends into subdirectories by default.
How do I find empty files in one folder only?
Use find /path/to/folder -maxdepth 1 -type f -empty. This checks the specified folder itself, not its child directories.
Does -empty find empty directories too?
It can match empty files or directories, depending on the type. Add -type f for files only, or use -type d -empty for empty directories.
Why is a blank-looking text file not found?
It likely contains at least one byte, such as a newline or spaces. -empty tests the actual byte size, not whether the file looks blank in an editor.
Can I delete all empty files with find?
Yes: find /specific/path -type f -empty -delete. Preview the matches first and verify the path, because empty files may be deliberately used by software.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.