dongtaotao19830418 2015-09-24 14:59
浏览 95
已采纳

如何在Go中使用多个iname匹配器执行find命令?

I need to execute this sort of command through the Go programming language:

find /some/dir/path -type f \( -iname \*.zip -o -iname \*.tar -o -iname \*.rar \)

I discovered exec.Command and tried various ways of executing the find command, e.g.

exec.Command("find", dir, "-type", "f", "\\( -iname \\*.zip -o -iname \\*.tar -o -iname \\*.rar \\)")
exec.Command("find", dir, "-type", "f", "-iname", "*.zip", "-o", "-iname", "*.tar", "-o", "-iname", "*.rar")
exec.Command("find", dir, "-type", "f", "\\(", "-iname", "\\*.zip", "-o", "-iname", "\\*.tar", "-o", "-iname", "\\*.rar", "\\)")

None of the above have worked for me. Is there a way to do this, or am I just going to have to issue 3 separate find commands in Go?

  • 写回答

1条回答 默认 最新

  • dongyilai4214 2015-09-24 15:11
    关注

    exec.Command isn't a shell, so you don't need to escape special characters in your command. Pass each argument in exactly how you want it processed by the command.

    exec.Command("find", dir, "-type", "f", "(", "-iname", "*.zip", "-o", "-iname", "*.tar", "-o", "-iname", "*.rar", ")")
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料