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
1 |
forfiles /S /M *.* /C "cmd /c if @fsize EQU 0 (if @isdir EQU FALSE echo @path)" > list.txt |
Linux
Since I made it for Windows, I thought it could do the same with Linux. Here's the one-liner:
1 |
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!
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)”