finding a string in a directory
Jun. 7th, 2013 03:02 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
![[community profile]](https://www.dreamwidth.org/img/silk/identity/community.png)
Little trick I do all the time when I'm looking for a string in a source tree:
find . -type f -exec egrep -H "string I'm seeking" {} \;
The things that vary:
find . -type f -exec egrep -H "string I'm seeking" {} \;
The things that vary:
find base command, doesn't change . the top directory you're seeking in. Could put a relative or absolute path here. -type f Narrowing down the kind of files you're seeking, in this case to regular files. You could narrow it down in other ways, e.g. -name "*.c" -exec egrep -H "string I'm seeking" {} \; the grep command in question. The only thing I have a very here is the egrep switch (and the string). -H lists filename and the match -l just lists the filename; less informative but cleaner. {} \; is necessary syntax for the exec argument to find.
no subject
Date: 2013-06-07 09:28 pm (UTC)no subject
Date: 2013-06-07 10:46 pm (UTC)(In other words, hey, I leanred a new egrep switch today. *g*)
no subject
Date: 2013-06-11 09:15 am (UTC)