UNIX / Linux: Find All Empty Files

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:

ADVERTISEMENTS

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.

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
2 comments… add one
  • Subin Jan 9, 2012 @ 6:40

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

  • Senthil Jan 10, 2012 @ 9:56

    Hi subin,

    Here’s ans to ur query..
    find . -name “DSD*.zip” -size 0b -exec ls -l {} \;

    – senthil

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.