UNIX / Linux Find All Empty Files Command

To find all empty files on a UNIX/Linux system, you can use the find command along with the size option and the exec option to execute a command on each file that matches the size criterion.

Here’s the command to find all empty files:

find /path/to/search -type f -size 0 -exec ls -l {} \;

In this command:

  • /path/to/search is the directory or path where you want to search for empty files. You can specify any directory or path that you want to search.
  • -type f specifies that you want to search for regular files only, not directories or other types of files.
  • -size 0 specifies that you want to search for files with a size of 0 bytes.
  • -exec ls -l {} \; specifies that for each file that matches the search criteria, you want to execute the ls -l command to display the file details.

This command will output a list of all empty files with their details, including the file name, size, and timestamp. If you want to delete the empty files, you can replace the ls -l command with the rm command, like this:

find /path/to/search -type f -size 0 -exec rm {} \;

This will delete all empty files in the specified directory or path. Be careful when using the rm command, as it will permanently delete the files without any confirmation.

(https://nwgapublichealth.org/)

Leave a Comment