Search code examples
windowscmdnul

How to write NUL to all log files in a folder using windows command line


I have multiple log files that start as ABC_.log in a windows environment. I want to clean that file (like writing /dev/null to file in linux). I need to do it through command line.

What I tried:

cmd:$ break > ABC_*.log

and

cmd:$ type NUL > ABC_*.log

Error:

 The filename, directory name, or volume label syntax is incorrect

Solution

  • this can't be done via wildcard (not possible to redirect to more than one file at a time). Use a for loop to process each file on it's own:

    for %%a in (ABC_*.log) do (
      break>"%%a"
    )
    

    or directly on command line:

     for %a in (ABC_*.log) do  break>"%a"