简体   繁体   English

如何使用Windows命令行将NUL写入文件夹中的所有日志文件

[英]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. 我有多个在Windows环境中以ABC_.log开头的日志文件。 I want to clean that file (like writing /dev/null to file in linux). 我想清理该文件(例如在Linux中将/ dev / null写入文件)。 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

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循环自行处理每个文件:

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

or directly on command line: 或直接在命令行上:

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

The easiest way to empty a file in UNIX/Linux: 在UNIX / Linux中清空文件的最简单方法是:

rm <filename>
touch <filename>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Windows命令行打开所有mp3文件? - How to open all mp3 files using windows command line? 命令行(或批处理文件)重命名文件夹中的所有文件 (Windows) - Command Line (or batch file) rename all files in a folder (Windows) 如何使用 windows 命令将所有文件从父文件夹中移动到新的子文件夹中? - How to move all files excecpt one from parent folder into a new child folder using windows command? 如何使用Windows cmd命令将所有文件移动到父文件夹 - How can I move all files to the parent folder using windows cmd command 复制包含文件的文件夹和子文件夹,但使用Windows命令行跳过根文件夹中的文件 - Copy folder and sub folders with files but skip files in root folder using windows command line 使用Windows命令行删除\\ bin目录中的所有文件 - Delete all files in \bin directories using the Windows command line 如何使用 python 真正删除文件夹中的所有文件和 Windows 上的文件夹? - How to really delete all files in a folder and the folder on Windows using python? 如何使用Windows命令行找到所有exe文件? - how do I find all exe files using command line for windows? 如何使用特定用户的命令行查看 Windows 中的文件夹权限? - How to view folder permission in windows using command line for particular user? 如何使用Windows命令将文件夹结构和文件复制到目标位置? - How to copy the folder structure and files into the destination using a Windows command?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM