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:
forfiles /S /M *.* /C "cmd /c if @fsize EQU 0 (if @isdir EQU FALSE echo @path)" > list.txt
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.
Since I made it for Windows, I thought it could do the same with Linux. Here’s the one-liner:
find ./ -type f -size 0 > list.txt
Again, if you want them on screen, remove the > list.txt at the end.
That’s about it!