UNIX / Linux: Find All Empty Files

in Categories last updated July 3, 2010

How do I find out all empty file under Linux and UNIX operating systems?

The gnu find command can use as follows to print list of all empty files:

find  /path/to/dest -type f -empty
# find all empty files in /tmp directory
find  /tmp -type f -empty

Find all Empty Directories

Type the following command:

find  /path/to/dest -type d -empty
# find all empty files in /tmp directory
find  /tmp -type d -empty

Sample outputs:

/tmp/orbit-gdm
/tmp/.exchange-vivek
/tmp/VMwareDnD
/tmp/virtual-vivek.O1nNU0

Find Empty File And Delete Them

Type the following command:

find  /path/to/dest -type f -empty -delete
# find all empty files in /tmp directory and delete them
find  /tmp -type f -empty -delete

Find Empty File Owned By A User Called vivek

Type the following command:

find  /path/to/dest -type f -empty -user vivek
# find all empty files in /tmp directory and delete them
find  /tmp -type f -empty -user vivek
# find all empty files owned by vivek and delete them, in /tmp
find  /tmp -type f -empty -user vivek -delete

The above commands are tested on GNU version of find and FreeBSD version of find command. Please refer to your local find command man page for exact details.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Share this on (or read 2 comments/add one below):

2 comment

  1. Can you please help me to get a unix script to list out the 0kb files of pattern DSD*.zip in a particular folder.

    Have a question? Post it on our forum!