Find the file that contains the keyword in linux
By:Roy.LiuLast updated:2021-02-03
This article shows how to find the file that contains the keyword in linux.
1. Environment
Centos7_x64
2. Prepare shell script find.sh
DIR=$1 KEY=$2 for FILE in $(find $DIR -type f); do if grep $KEY $FILE &>/dev/null; then echo "--> $FILE" fi done
3. How to use this script
./find.sh /var/nginx/log BusinessException
The first parameter is the location you want to search.
Thie second parameter is the keyword you want to search.
From:Is Everything OK
COMMENTS