How to find and list zero byte files in Windows and Linux A single-line Command Prompt script that will help you to locate all zero-byte files on your Windows or Linux machine and print them on screen or file

How to execute PHP7 CLI commands with cPanel and EasyApache 4 - PHP7 CLI path

Today I was asked to write a simple batch script to locate all zero-byte files within a Windows Server machine.

The answer was definitely simple, thanks to the powerful FOR command available in cmd.exe:

Windows

This will create a list.txt file containing all the zero-byte files found within the current execution folder and all its subdirectories. If you want them on screen, simply remove the > list.txt at the end.

Linux

Since I made it for Windows, I thought it could do the same with Linux. Here's the one-liner:

Again, if you want them on screen, remove the > list.txt at the end.

That's about it!

 

About Ryan

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites & services hosted in Italy and Europe. Since 2010 it's also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies. Microsoft MVP for Development Technologies since 2018.

View all posts by Ryan

One Comment on “How to find and list zero byte files in Windows and Linux A single-line Command Prompt script that will help you to locate all zero-byte files on your Windows or Linux machine and print them on screen or file

  1. forfiles /S /M . /C “cmd /c if @fsize EQU 0 (if @isdir EQU FALSE echo @path)”
    That’s a nice one liner script. is it possible to specify certain specific multiple locations like
    forfiles /S /M c:\searchhere c:\andhere c:\onemorehere . /C “cmd /c if @fsize EQU 0 (if @isdir EQU FALSE echo @path)”

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

This site uses Akismet to reduce spam. Learn how your comment data is processed.