执行搜索之前,Gnuwin32 find.exe会扩展通配符 [英] Gnuwin32 find.exe expands wildcard before performing search

查看:168
本文介绍了执行搜索之前,Gnuwin32 find.exe会扩展通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows环境中使用Gnuwin32二进制文件。
当我想要查找某种类型的文件时,比如说PDF,我通常运行:

  find。 -iname'* .pdf'-print 

这对任何UNIX系统都是完美的。

  find.exe。 -iname* .pdf-print 

但是在Windows下,单引号替换为双引号,只有当前目录中没有pdf文件的情况下才能正常工作,否则 * 会被扩展。

更糟:当前目录中只有一个PDF文件时,它会展开,不会有语法错误,并且会得到错误的结果。

<我已经尝试用插入符号,反斜线和星号来转义 * ,并在里面加双引号:

实际例子:

好的,这里是我的所有文件:

  C:\ tmp>查找。 -type f 
./a/1.pdf
./a/2.pdf
./a/aa/1.pdf
./b/1.pdf
./b/bb/1.pdf
./b/bb/2.pdf

良好的行为,通配符不被扩展。 -iname* .pdf
./a/1.pdf
./a/2.pdf
./a/aa/1.pdf
./b/ 1.pdf
./b/bb/1.pdf
./b/bb/2.pdf

C:\ tmp> cd a

注意,行为不一致,通配符已扩展:

  C:\ tmp \ a>查找。 -iname* .pdf
find:路径必须在表达式
之前使用:find [-H] [-L] [-P] [path ...] [expression]

C:tmp \ a> cd ..\\b

注意,行为不一致,通配符已扩展:

  C:\ tmp \ b> find。 -iname* .pdf
./1.pdf
./bb/1.pdf

谢谢

解决方案

我发现自己解决了我的问题。




I am using Gnuwin32 binaries on a Windows environment.
When I want to find files of a certain type, let's say PDF, I usually run:

find . -iname '*.pdf' -print

This works perfectly on any UNIX system.

find.exe . -iname "*.pdf" -print

But under Windows, having replaced single quotes with double-quotes, it only works when there is no pdf file in the current directory, otherwise the * gets expanded.

Worse: when there is exactly one PDF file in the current directory, it will expand, there will be no syntax error and you will get wrong results.

I have tried escaping the * with a caret, a backslash, a star itself, putting inside double quotes: nothing works for me.

Real example:

Okay, here are all my files:

C:\tmp>find . -type f
./a/1.pdf
./a/2.pdf
./a/aa/1.pdf
./b/1.pdf
./b/bb/1.pdf
./b/bb/2.pdf

Good behaviour, wildcard was not expanded

C:\tmp>find . -iname "*.pdf"
./a/1.pdf
./a/2.pdf
./a/aa/1.pdf
./b/1.pdf
./b/bb/1.pdf
./b/bb/2.pdf

C:\tmp>cd a

Caution, inconsistent behaviour, wildcard was expanded:

C:\tmp\a>find . -iname "*.pdf"
find: paths must precede expression
Usage: find [-H] [-L] [-P] [path...] [expression]

C:tmp\a>cd ..\b

Caution, inconsistent behaviour, wildcard was expanded :

C:\tmp\b>find . -iname "*.pdf"
./1.pdf
./bb/1.pdf

Thank you

解决方案

I have found myself the solution to my problem.

这篇关于执行搜索之前,Gnuwin32 find.exe会扩展通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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