Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.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 查找一个文件(不区分大小写)并将真实文件名(区分大小写)返回到变量中_Linux_Unix_Filenames - Fatal编程技术网

Linux 查找一个文件(不区分大小写)并将真实文件名(区分大小写)返回到变量中

Linux 查找一个文件(不区分大小写)并将真实文件名(区分大小写)返回到变量中,linux,unix,filenames,Linux,Unix,Filenames,我知道我有一个文件。 我知道这个文件是Hello.txt,或Hello.txt,或Hello.txt,或其他大小写变体 因此,我可以使用以下方法查找此文件: find . -iname hello.txt 它找到了 如何将实名(“HelLO.txt”)放入linux变量中?最简单的方法: var=`find . -iname hello.txt` 注意,这会将所有匹配的文件名分配给变量,因此如果您有多个变量(Hello等),那么您将在变量中获得所有变量 var=`find . -iname

我知道我有一个文件。
我知道这个文件是Hello.txt,或Hello.txt,或Hello.txt,或其他大小写变体

因此,我可以使用以下方法查找此文件:

find . -iname hello.txt
它找到了

如何将实名(“HelLO.txt”)放入linux变量中?

最简单的方法:

var=`find . -iname hello.txt`
注意,这会将所有匹配的文件名分配给变量,因此如果您有多个变量(Hello等),那么您将在变量中获得所有变量

var=`find . -iname hello.txt | head -n1 | sed 's/.*\///g'`

应该做你想做的。

这不是返回整个路径吗?谢谢。仅为其他读者提供文档:header-n1获取第一个结果,sed“…”应用一个正则表达式,以便它只捕获文件名,而不捕获整个路径