How to find files with a specific pattern in the parent and child directory of my present working directory using a single command ?
Filename - test.txt, the file has the pattern nslookup
This file is present in 3 directories and they are /home, /home/1 and /home/1/2
I am currently at /home/1. I have tried below commands :
find ../ -type f -name "test.txt"
Output :
../test.txt
../home/1/test.txt
../home/1/2/test.txt
I was able to find the files, hence I tried the below command :
$ find ../ -type f -exec grep "nslookup" {} \;
nslookup
nslookup
nslookup
This doesn't display the file names.
Command :
find . -type f -name "test.txt" | xargs grep "nslookup"
==> gives me files in pwd and child directories :
./1/test.txt:nslookup
./test.txt:nslookup
but when I try to search in the parent directory as shown below the results are erroneous :
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 -irn
?