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
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!