Linux在指定目录下查找包含指定字符串的文件

本文介绍了在Linux系统中查找包含指定字符串的文件的多种方法,包括使用`which`、`whereis`、`locate`、`find`和`grep`命令。特别是通过`grep -rm`结合`find`在 `/var/www/doudou` 目录下进行查询,以及使用`find`和`xargs`配合`grep`在 `/home/ews/dvlp/EWS_INSERT` 目录下查找包含特定字符串的`.log.*`文件。
摘要由CSDN通过智能技术生成

第一种方法:

#!/bin/bash

echo -e "\nThis is a program to find the file in special directory which include keyword!\n\n"

if [ "$1" == "" ]; then
       echo -e "Please input the keyword behind the $0\.\n\n"
      exit 0
fi

keyword=$1

dir=.
if [ "$2" != "" ]; then
      dir=$2
fi

test ! -d $dir && echo -e "The $dir is not exist in your system\.\n\n" && exit 0

count=0
filelist=`ls -R $dir 2> /dev/null | grep -v '^$'`
for filename in $filelist
do
      temp=`echo $filename | sed 's/:.*$//g'`
      if [ "$filename" != "$temp" ]; then
              curdir=$temp
            #echo "current dir = $curdir"
      e
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值