A basic syntax for searching text with grep command:

The grep command offers other useful options for finding specific text in file systems.

-r, –recursive: Search files recursively -R, –dereference-recursive: Search files recursively and follow symlinks –include=FILE_PATTERN: search only files that match FILE_PATTERN –exclude=FILE_PATTERN: skip files and directories matching FILE_PATTERN –exclude-from=FILE: skip files matching any file pattern from FILE –exclude-dir=PATTERN: directories that match PATTERN will be skipped. -L, –files-without-match: Print file names containing no match -l, –files-with-matches: Print string containing file names only -i, –ignore-case: ignore case of search string -e, –regexp=PATTERN: Use a pattern to search or specify multiple search strings -w, –word-regexp: force to match whole words

There are several ways to use the grep command to search text. Let’s discuss a few examples of searching a text/string in the file system.

Conclusion

You have learned how to search for specific text in files on the Linux file system in this tutorial.

How to find all files containing specific text in Linux   TecAdmin - 67How to find all files containing specific text in Linux   TecAdmin - 29