'grep -l'不适用于具有子文件夹的文件夹 [英] 'grep -l' is not working for a folder with sub folders

查看:193
本文介绍了'grep -l'不适用于具有子文件夹的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图搜索文件内容。该文件位于具有子文件夹的目录中。



命令

  grep -l'关键字'

正在工作并且正在查找文件夹下的所有文件。如果我在包含子文件夹的文件夹中搜索,我没有得到任何结果。



有什么方法可以使用目录级搜索来搜索文件内容吗?

解决方案

您需要这样做:

  find。 -type f -exec grep -l'keyword'{} \; 

您也可以用 -name 选项并给它一个shell正则表达式,例如'* .txt'。



其中'。'是您所在的当前文件夹 - 您也可以给任何目录路径而不是'。'来搜索给定的文件夹。



请参阅: man find


I am trying to search for file contents. The file is in a directory with sub folders.

The command

grep -l 'keyword'

is working and is finding all files which are under a folder. If I am searching in a folder with subfolders, I am not getting any results.

Is there any way to search file contents using a directory level search?

解决方案

You need to do something like this:

find . -type f -exec grep -l 'keyword' {} \;

You can also limit the find with the -name option and give it a shell regular expression, for example, '*.txt'.

Where '.' is the current folder you're in -- you can also give any directory path instead of '.' to search a given folder.

See: man find

这篇关于'grep -l'不适用于具有子文件夹的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆