In Windows, I would have done a search for finding a word inside a folder. Similarly, I want to know if a specific word occurs inside a directory containing many sub-directo
There's also:
find directory_name -type f -print0 | xargs -0 grep -li word
but that might be a bit much for a beginner.
find
is a general purpose directory walker/lister, -type f
means "look for plain files rather than directories and named pipes and what have you", -print0
means "print them on the standard output using null characters as delimiters". The output from find
is sent to xargs -0
and that grabs its standard input in chunks (to avoid command line length limitations) using null characters as a record separator (rather than the standard newline) and the applies grep -li word
to each set of files. On the grep
, -l
means "list the files that match" and -i
means "case insensitive"; you can usually combine single character options so you'll see -li
more often than -l -i
.
If you don't use -print0
and -0
then you'll run into problems with file names that contain spaces so using them is a good habit.
grep -R "string" /directory/
-R follows also symlinks when -r does not.