Originally Posted by skaushal_lk
you can try this way also:
find .-name *.* | xargs grep "string"
That won't even work as written. It seems like a very complex solution to this simple problem anyway.
The "." is not needed if you want to find files in the current directory. You may omit it.
find .-name *.*
find: .-name: No such file or directory
To make this work you need a space between the "." and the "-".
The next problem you will face is that the "*.*" will be expanded by the shell, not the find command. As an example, assume the current directory contains three files as shown below:
The fully expanded find command will look like this:
The reason no file names are included in the expansion is because none of the file names in the current directory contain the "." character. As far as the shell is concerned pattern "*.*" literally means "all file names containing ."
I could go on with all the problems with this find construction, but in deference to the OP I'll cut to the chase.
If you want to search for text in a single file use this.
grep 'text to search for' filename
Often you are uncertain whether certain letters are upper case or lower case, so use this:
grep -i 'text to search for' filename
You can search a group of files in a single directory by using a pattern instead of filename
# search all ".txt" files in the current dir
grep -i 'text to search for' *.txt
# search all files in the current dir
grep -i 'text to search for' *
When specifying file names and patterns remember that file names are case sensitive on Linux!
grep -i 'text to search for' *.TXT
You can search all files within a directory tree, but it may take some time depending on how many files and how deeply nested they are:
grep -i -R 'text to search for' *.txt
Finally, remember that 'text to search for'
is a regular expression, not a simple pattern. If you need to search for anything more complex than exact text matches then you should read up on regular expressions.