Unix 如何使用单个命令在当前工作目录的父目录和子目录中查找具有特定模式的文件?
如何使用单个命令在当前工作目录的父目录和子目录中查找具有特定模式的文件 Filename-test.txt,该文件的模式为“nslookup” 此文件存在于3个目录中,它们是/home、/home/1和/home/1/2 我现在在家。我尝试了以下命令:Unix 如何使用单个命令在当前工作目录的父目录和子目录中查找具有特定模式的文件?,unix,Unix,如何使用单个命令在当前工作目录的父目录和子目录中查找具有特定模式的文件 Filename-test.txt,该文件的模式为“nslookup” 此文件存在于3个目录中,它们是/home、/home/1和/home/1/2 我现在在家。我尝试了以下命令: find ../ -type f -name "test.txt" Output : ../test.txt ../home/1/test.txt ../home/1/2/test.txt 我能够找到文件,因此我尝试了以下命令: $ find
find ../ -type f -name "test.txt"
Output :
../test.txt
../home/1/test.txt
../home/1/2/test.txt
我能够找到文件,因此我尝试了以下命令:
$ find ../ -type f -exec grep "nslookup" {} \;
nslookup
nslookup
nslookup
这不会显示文件名
命令:
找到-键入f-name“test.txt | xargs grep”nslookup'=>以
pwd和子目录:
./1/test.txt:nslookup
./test.txt:nslookup
但是,当我尝试在父目录中搜索时(如下所示),结果是错误的:
find ../ -type f -name "test.txt" | xargs grep "nslookup
User@User-PC ~/test
$ uname -a
CYGWIN_NT-6.1 User-PC 2.5.2(0.297/5/3) 2016-06-23 14:29 x86_64 Cygwin
这个怎么样:
grep -r -l nslookup .. | grep test.txt