Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 使用bash通配符定位行为_Linux_Bash_Shell - Fatal编程技术网

Linux 使用bash通配符定位行为

Linux 使用bash通配符定位行为,linux,bash,shell,Linux,Bash,Shell,我有 为什么这会给出0个匹配项 $ ls -l re*trict ls: cannot access re*trict: No such file or directory 不过,这是可行的,并提供了8351个匹配项: $ locate -c 're*trict' 0 $ locate -c re*trict 0 $ locate -c re?trict 0 locate与完整路径名匹配。要将re*trict作为子字符串查找,必须在其前后添加*: $ locate -c restrict 8

我有

为什么这会给出0个匹配项

$ ls -l re*trict
ls: cannot access re*trict: No such file or directory
不过,这是可行的,并提供了8351个匹配项:

$ locate -c 're*trict'
0
$ locate -c re*trict
0
$ locate -c re?trict
0

locate
与完整路径名匹配。要将
re*trict
作为子字符串查找,必须在其前后添加
*

$ locate -c restrict
8351

我想答案可以在手册页上找到:

如果任何模式不包含全局字符,则locate的行为与模式为*模式*的行为相同


因为我的模式包含一个全局字符,所以它没有扩展到*PATTERN*,所以试图找到一个文本匹配。显然,没有名为(替换为s)
'restrict'
的文件,因为即使在根目录下,该文件的名称也将是
/re?trict
,并且匹配将失败,因为前导的
/
locate restrict
列出了
restrict
显示为子字符串的路径。“如果任何
模式
不包含全局字符,则locate的行为就像模式是
*模式*
”(man locate),如果模式确实包含全局字符,则它会尝试查找与完整路径名完全匹配的文字…对吗?是。(允许发布的更多字符)
locate '*re*trict*'