How to Find All Files with File Size Zero (0) Bytes in a Directory Recursively

»»»How to Find All Files with File Size Zero (0) Bytes in a Directory Recursively

In Linux operating system, to find and print the name of all files that has the file size 0 (zero) bytes, in a directory and all its sub-directories recursively, use one of the following commands:

find /path/to/directory/ -size 0 -type f

Or,

find /path/to/directory/ -size 0 -type f -print

Replace /path/to/directory/ with actual directory that you want to check. You can use “.” (dot without quotes) to list all files with file size of 0 bytes in the current directory. The “-type f” argument specifies that only regular file type is returned, excluding other file types such as symbolic link, socket, directory, named pipe and etc. Some Linux distributions may require “-print” command to print out the filenames.

To filter and display just files with certain pattern, for example, only files with .log file extension, use “-name” option:

find /path/to/directory/ -size 0 -type f -name "*.log"

Once you have view and verify the list of files that have file size 0, you can easily delete all of them by appending the ‘-delete’ option. For example:

find /path/to/directory/ -size 0 -type f -delete

By |2017-01-20T16:45:40+00:00January 20th, 2017|Categories: Linux|Tags: , |0 Comments

About the Author:

LK is a technology writer for Tech Journey with background of system and network administrator. He has be documenting his experiences in digital and technology world for over 15 years.Connect with LK through Tech Journey on Facebook, Twitter or Google+.

STAY IN TOUCH

close-link