UNIX / Linux Find All Empty Files Command

‮/:sptth‬/www.lautturi.com
UNIX / Linux Find All Empty Files Command

To find all empty files in a directory on a Unix or Linux system, you can use the find command with the -empty option.

Here is the basic syntax for using the find command to find empty files:

find path -type f -empty

The path argument specifies the directory to search, the -type f option tells find to search for files only, and the -empty option tells find to search for empty files.

For example, to find all empty files in the current directory, you can use the following command:

find . -type f -empty

This will search the current directory (.) for empty files and display a list of the empty files found.

You can also specify a different directory to search using the path argument.

For example, to find all empty files in the /var/log directory, you can use the following command:

find /var/log -type f -empty

You can use the -printf option to print a custom message for each empty file found.

For example:

find . -type f -empty -printf '%p is an empty file\n'

This will search the current directory for empty files and print a message for each empty file found, including the path of the empty file.

Created Time:2017-10-30 14:27:23  Author:lautturi