找到的bash shell命令和-name选项疑虑 [英] find command in bash shell and the -name option doubts
问题描述
什么是以下两者的区别:
What is the difference between the two below:
find . -type f -name \*.bmp
find . -type f -name *.bmp
我已经测试过,他们都返回相同的结果,所以有什么不同的 _deep内_
?
从删除答案补充:
所以这是为了避免对特殊字符*****外壳扩展,只透过*作为参数传递给find命令,让它进行处理。
So it is to avoid the shell expansion for the special ***** character,solely pass * as a argument to the find command and let it process it.
不过,我的机器上,他们都好,都返回BMP文件和当前目录下,仅举几例,结果如下图所示,有些是为了简明扼要省略
But on my machine,they are all good, both return the bmp files in and below the current directory,to name a few,the result is like below,some are omitted for brevity
./images/building_color.bmp
./images/building_gray.bmp
./images/car_gray.bmp
./images/temple_color.bmp
./images/boat_gray.bmp
./images/tools_gray.bmp
./images/temple_gray.bmp
./images/tools_color.bmp
./images/car_color.bmp
./images/boat_color.bmp
系统信息:
GNU的bash,版本4.1.5(1) - 释放(的i486-PC-Linux的GNU)
GNU bash, version 4.1.5(1)-release (i486-pc-linux-gnu)
Linux的sysabod-笔记本2.6.32-30泛型#59,Ubuntu的SMP周二3月1日21点30分21秒UTC 2011 i686的GNU / Linux的
Linux sysabod-laptop 2.6.32-30-generic #59-Ubuntu SMP Tue Mar 1 21:30:21 UTC 2011 i686 GNU/Linux
推荐答案
下面就是他们是不同的:第一个总是工作,而第二个没有
Here's how they're different: the first one always works, and the second one doesn't.
至于为什么:在bash,shell通配符(通配符包括*或?)由外壳到相匹配的水珠所有文件展开。但是,如果不存在这样的文件,图案被单独留下。
As for why: in bash, shell globs (wildcard patterns including * or ?) are expanded by the shell into all files matching the glob. However, if no such files exist, the pattern is left alone.
所以,如果你在没有 BMP
文件的目录是,这些命令的工作方式相同,因为第一个转义和bash没有找到匹配的任何文件在第二种情况下
So, if you're in a directory with no bmp
files, the commands work the same way, because the first is escaped and bash fails to find any files matching in the second case.
如果你只包含一个这样的文件的目录跑了出来,说 foo.bmp
,首先会发现所有的 BMP
的子树中的文件,而第二个会找到名为 foo.bmp
只有所有文件。如果有多个 BMP
文件的目录中运行,我相信,因为找到
不知道你会得到一个错误如何处理所有的文件名。
If you ran it from a directory containing only one such file, say foo.bmp
, the first would find all bmp
files in the subtree, while the second would find all files named foo.bmp
only. If run in a directory with multiple bmp
files, I believe you'll get an error because find
doesn't know what to do with all the filenames.
这篇关于找到的bash shell命令和-name选项疑虑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!