Debug School

rakesh kumar
rakesh kumar

Posted on

How to find string in partiular file using linux command with example

The "grep" command is commonly used in Linux to search for a specific string in a file.

Here's an example:

grep "search_string" file_name.txt
Enter fullscreen mode Exit fullscreen mode

In this example, search_string is the string you're searching for, and file_name.txt is the name of the file you want to search in.

If you want to search for a string in all files in the current directory, you can use the following command:

grep -r "search_string" .
Enter fullscreen mode Exit fullscreen mode

The -r option is used to search recursively in all subdirectories. The . at the end specifies the current directory.

Note that grep is case-sensitive by default, but you can make it case-insensitive using the -i option:

grep -i "search_string" file_name.txt
Enter fullscreen mode Exit fullscreen mode

Top comments (0)