Bash shell脚本,用于查找与字符串匹配的文件夹(包含子文件夹)中的文件名

Bash shell脚本,用于查找与字符串匹配的文件夹(包含子文件夹)中的文件名,bash,shell,filesystems,Bash,Shell,Filesystems,我想编写一个shell脚本,将文件名与运行时在命令行中输入的给定字符串相匹配。我希望能够匹配文件名中的模式。 例如,如果字符串是'questi',文件夹中包含'question1.c','question2.c',questions.doc',这些应该显示为答案。脚本可以如下所示: $!/bin/bash shopt -s nullglob # To return nothing if there is no match. echo *$1* 然后将其命名为script.sh quest

我想编写一个shell脚本,将文件名与运行时在命令行中输入的给定字符串相匹配。我希望能够匹配文件名中的模式。
例如,如果字符串是'questi',文件夹中包含'question1.c','question2.c',questions.doc',这些应该显示为答案。

脚本可以如下所示:

$!/bin/bash
shopt -s nullglob    # To return nothing if there is no match.
echo *$1*

然后将其命名为
script.sh questi

这可以使用
find

find /path/to/directory -type f -iname "*questi*"
选项
-type f
只返回文件,
-iname
在glob
*questi*
上进行不区分大小写的匹配,因此应返回'question1.txt'、'five_questions.txt'等

如果您希望将其放入shell脚本中,如下所示:

#!/bin/sh
find $1 -type f -iname "*$2*"

把它叫做:
filefind.sh/path/to/directory questi

这是你的家庭作业吗?