使用脚本需要识别在给定路径下包含特定关键字的所有文件或文件夹。该路径将有多个文件夹。 下面是使用的脚本。
#!/bin/sh
DIR=''
for FILE in ls "$DIR"*
do
# echo $FILE
grep -l $FILE "*FY*"
done
~
答案 0 :(得分:0)
您必须在要搜索的路径之前输入“关键字”。脚本中不是这种情况。
grep -l -r "keyword" path/to/folder
尝试上面的脚本。
-l, --files-with-matches
Suppress normal output; instead print the name of each input
file from which output would normally have been printed. The
scanning will stop on the first match. (-l is specified by
POSIX.)
-R, -r, --recursive
Read all files under each directory, recursively; this is
equivalent to the -d recurse option.
有关更多信息,refer