Sed 在 Windows 中创建不可删除的文件 [英] Sed creates un-deleteable files in Windows

查看:40
本文介绍了Sed 在 Windows 中创建不可删除的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Windows Server 2003 中运行以下命令,但 sed 创建了一堆文件,我无法从当前目录内的命令行中删除这些文件.

I'm trying to run the following command in Windows Server 2003 but sed creates a pile of files that I can't delete from the command line inside the current directory.

for/R %f in (*.*) do "C:\Program Files\gnuwin32\bin\sed.exe" -i "s/bad/good/g" "%f"

有人有什么建议吗?奇怪的是,我可以使用 Windows 资源管理器删除这些文件.

Does anyone have any suggestions? Mysteriously enough, I'm able to delete the files using Windows Explorer.

根据要求,以下是一些示例文件名:

As requested, here are some example filenames:

  • sed0E3WZJ
  • sed5miXwt
  • sed6fzFKh

还有更多故障排除信息...

And, more troubleshooting info...

  • 它发生在命令提示符和批处理文件
  • 如果我只需要在单个目录上运行 sed,那么我使用 sed "s/bad/good/g" *.* 一切正常.唉,我还需要它来处理所有子目录.
  • 我只安装了 Sed.
  • Sed 正在创建文件
  • It occurs from both the command prompt & batch files
  • If I just need to run sed on a single directory, then I use sed "s/bad/good/g" *.* and everything is OK. Alas, I also need it to tackle all the subdirectories.
  • I only have Sed installed.
  • Sed is creating the files

推荐答案

我已经复制了您的设置,我有以下观察结果.

I have replicated your setup and I have the following observations.

  1. 我认为循环中没有问题.简单的命令 "C:\Program Files\gnuwin32\bin\sed.exe" -i "s/bad/good/g" . - 创建相同的临时文件集.
  2. 这些文件确实是由 sed 创建的.当就地"(-i) 选项打开时,sed 会创建这些临时文件.在正常过程中,sed 实际上是通过调用unlink"库来删除文件(这就是 cygwin 中发生的情况).在 gnuwin32 的情况下,看起来取消链接"失败.我一直无法弄清楚为什么.我猜测可能 unlink 调用依赖于 gnuwin32 'coreutils' 库,并尝试下载并安装 coreutils 库 - 没有骰子.
  3. 如果在执行 sed 命令之前删除父文件夹中的只读"限制,则可以从 Windows 命令提示符删除临时文件.所以这应该会给你一些暂时的喘息机会.
  1. I dont think there is a problem in the loop. The simple command "C:\Program Files\gnuwin32\bin\sed.exe" -i "s/bad/good/g" . - creates the same set of temporary files.
  2. The files are indeed created by sed. sed creates these temporary files when the "in place" (-i) option is turned on. In the normal course, sed actually deletes the files (that is what happens in cygwin) using a call to the 'unlink' library. In case of gnuwin32, it looks like the 'unlink' fails. I have not been able to figure out why. I took a guess that maybe the unlink call is dependent on the gnuwin32 'coreutils' library and tried to download and install the coreutils library - no dice.
  3. If you remove the 'read-only' restriction in the parent folder before executing the sed command, you can delete the temporary files from windows command prompt. So that should give you some temporary respite.

我认为我们现在有足够的信息来提交错误报告.如果您同意,我认为将其告知负责 gnuwin32 的好人并向他们寻求帮助可能是个好主意.

I think we now have enough information to raise a bug report. If you agree, I think it may be a good idea to bring it to the notice of the good folks responsible for gnuwin32 and ask them for help.

与此同时,以下版本会清理其临时文件:

Meanwhile, the following version cleans up its temporary file:

这篇关于Sed 在 Windows 中创建不可删除的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆