is it possible to find the file which contains a s

2020-03-31 06:39发布

Consider this situation where i have many files under a folder "Example".And if i need to find a file which contains a specific phrase like "Class Example", how do i do it with a linux shell?

is there any "locate" like functions in linux to do this?

Thanks,

Balan

标签: linux shell
5条回答
爱情/是我丢掉的垃圾
2楼-- · 2020-03-31 06:50

Use good ol' grep:

grep -R "Class Example" Example

where "Class Example" is the search string and Example is the directory, and -R specifies recursive search.

查看更多
ら.Afraid
3楼-- · 2020-03-31 06:50

If you want a gui, and/or fast results,Beagle is a nice solution that I use. Beagle Main Page.

查看更多
Summer. ? 凉城
4楼-- · 2020-03-31 07:03

You can do this using egrep "text1|text2" * or using grep, and cscope is also a good tool for searching and editing..

查看更多
▲ chillily
5楼-- · 2020-03-31 07:06

You can try something like this:

find Example | xargs grep 'Class Example'
查看更多
萌系小妹纸
6楼-- · 2020-03-31 07:13

List of file names containing a given text

You can use a combination of find with grep to find the list of filenames containing the text as below.

find /<path>/Example -name "*" -exec grep -l "Class Example" {} \; 

Even if you are not use about the case like "Class" vs "class", you can use the -i switch to ignore case. Also if you know the file extension, you can give that to the -name attribute. You can read further details here.

查看更多
登录 后发表回答