smeeb smeeb - 8 months ago 37
Linux Question

Shell-fu to list all files in a directory that contain instance of a word or phrase

Linux here. I'm trying to run some kind of shell-fu command against an arbitrary directory on my file system, and have it spit out all the files (searching recursively) inside that directory that contain at least one instance of a particular (quoted) phrase. So something like this:

someMagicCommand ~/some/path/to/a/dir -phrase "How now brown cow"

Where those 3 files (
, and
) all contain at least one instance of `"How now brown cow" inside of them. Don't care about anything other than the file names and their paths (which can be absolute or relative to the target directory, no preferences). But I specifically just want paths + names (not content dumps).

I've tried all manners of
variations but not even sure where to start here. Any ideas?


You can do this with a simple grep command

grep -rl "how now brown cow" /path/to/dir