tags:

views:

33

answers:

3

For example I have a /path/to/folder and want to see if it contains "keyword1", "keyword2" or "keyword3" and the result would be (when 2 are found):

/path/to/folder: keyword1 keyword3

I tried with options shown here but it doesn't work for folders.

+1  A: 

If you are talking about keywords in filenames

shopt -s nullglob
for file in *keyword1* *keyword2* *keyword3*
do
  echo "$file"
done

if you are talking about finding those keywords in the files that are in your folder, you can use tools like grep

grep -l -E "keyword1|keyword2|keyword3" *

if you need to show which keywords are found

grep  -Eo "keyword1|keyword3|keyword2" *
ghostdog74
It will almost do the trick except it doesn't output WHICH keywords were found.
Ragnar
+1  A: 
echo -n '/path/to/folder:'; for kw in {keyword1,keyword2,keyword3}; do grep -qr $kw /path/to/folder/; if [ $? == 0 ]; then echo -n " "$kw; fi; done
eumiro
Your answer helped the most. Thanks!
Ragnar
A: 
grep -E "keyword1|keyword3|keyword2" *

will return something like this:

file.one:This text contains keyword1.
file.two:The keyword2 can be found in this file.
file.six:This is a keyword enumeration: keyword1, keyword2, keyword3.

splash