How to search for a string in all the files irrespective of directory.?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to search for a string in all the files irrespective of directory.?
# 1  
Old 03-01-2016
How to search for a string in all the files irrespective of directory.?

Hi All,

How to search for a string in all the files irrespective of directory.

If I use
Code:
grep -i 'hello' *.*

It will search for the string hello in the files of current directory.

But I want to check for the string hello in the files of all the directories.

Thanks

Last edited by Don Cragun; 03-01-2016 at 04:53 AM.. Reason: Add CODE and ICODE tags.
# 2  
Old 03-01-2016
Hello ROCK_PLSQL,

Please use code tags while using Inputs/codes/commands into your posts as per forum rules.
You could go through the rules of forum into as follows link too.
https://www.unix.com/misc.php?do=cfrules

Now coming onto your requirement, could you please try following and let me know if this helps you.
Code:
find -type f -exec grep -l "test_text" {} \+

Please try above and let us know how it goes, if you have more conditions and requirements please mention all in post too.

NOTE: Above will provide you all the files details(only names of files) which have string test_text in them.

Thanks,
R. Singh

Last edited by RavinderSingh13; 03-01-2016 at 03:12 AM..
# 3  
Old 03-01-2016
Does your grep offer the -r option?
# 4  
Old 03-01-2016
Hi,

I have tried this
Code:
 find -type f -exec grep -l "hello" {} \+

got the error

Code:
find: illegal option -- t
find: [-H | -L] path-list predicate-list


Code:
grep -r

is not supporting.

Thanks

---------- Post updated at 07:32 PM ---------- Previous update was at 05:09 PM ----------

Hi ALL,

Please help me.

Thanks
# 5  
Old 03-01-2016
Quote:
Originally Posted by RavinderSingh13
Hello ROCK_PLSQL,

Please use code tags while using Inputs/codes/commands into your posts as per forum rules.
You could go through the rules of forum into as follows link too.
https://www.unix.com/misc.php?do=cfrules

Now coming onto your requirement, could you please try following and let me know if this helps you.
Code:
find -type f -exec grep -l "test_text" {} \+

Please try above and let us know how it goes, if you have more conditions and requirements please mention all in post too.

NOTE: Above will provide you all the files details(only names of files) which have string test_text in them.

Thanks,
R. Singh
That should be find . -type f -exec grep -l "test_text" {} + (with the dot and without the \)

Last edited by Scrutinizer; 03-01-2016 at 03:50 PM..
This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search strings from a file in files in a directory recursively; then print the string with a status

Hi All, I hope somebody would be able to help me. I would need to search a string coming from a file, example file.txt: dog cat goat horse fish For every string, I would need to know if there are any files inside a directory(recursively) that contains the string regardless of case.... (9 Replies)
Discussion started by: kokoro
9 Replies

2. UNIX for Beginners Questions & Answers

Search directory for string and print file name

Good Evening Folks - I have a need to search a specific directory and ALL sub-directories for the following string: Data Load UpdatedIf this string is found, I need to print content from the line directory above it between symbols, as well as the file name where it is found. Here is a... (1 Reply)
Discussion started by: SIMMS7400
1 Replies

3. Shell Programming and Scripting

Append string to all the files inside a directory excluding subdirectories and .zip files

Hii, Could someone help me to append string to the starting of all the filenames inside a directory but it should exclude .zip files and subdirectories. Eg. file1: test1.log file2: test2.log file3 test.zip After running the script file1: string_test1.log file2: string_test2.log file3:... (4 Replies)
Discussion started by: Ravi Kishore
4 Replies

4. Shell Programming and Scripting

logrotate irrespective of the size of a file/directory

hi, How to logrotate irrespective of the size of a file/directory...? Please help me in this regard... (4 Replies)
Discussion started by: Dedeepthi
4 Replies

5. UNIX for Dummies Questions & Answers

How to search all the files in a directory for a specific string

Hi Guys, I want to search the content of all the files (of a particular type like .txt) in a directory for a specific string pattern. Can anyone help me? Thanks (7 Replies)
Discussion started by: mwrg
7 Replies

6. UNIX for Dummies Questions & Answers

Search for a text within files in a directory

I need to search for a particular string. This string might be present in many files. The directory in which I am present has more than one subdirectories. Hence, the search should check in all the subdirectories and all the corresponding files and give a list of files which have the particular... (5 Replies)
Discussion started by: pakspan
5 Replies

7. Solaris

Search for string in a directory with binaries exclusion

Hi all, My need is to search for a given string "toto" within a directory, but the search should ignore binary and db files. It is in fact, a combination of xargs grep that I didn't succeed to manage. Let we say that we are under /etc/ and we want to search for all included files (except... (9 Replies)
Discussion started by: mdjebbi
9 Replies

8. Shell Programming and Scripting

search files in a directory and its subdirectories

Hello my friends, I need to write a simple shell bad file :D that search and delete a file it's name 'Microsoft.txt' in the current directory and its subdirectories? So can you help to guide me how i can write this shell, Just give me the beginning :o thank you. (1 Reply)
Discussion started by: Net-Man
1 Replies

9. UNIX for Dummies Questions & Answers

Unix find command to print directory and search string

Hi i need to print pathname in which the string present using 'find' command sample output like this Pathname String to be searched ---------- -------------------- /usr/test/myfile get /opt/test/somefile get Thanks in... (4 Replies)
Discussion started by: princein
4 Replies

10. Shell Programming and Scripting

search all files and sub directory

I wanted to search in all the sub directories under /vob/project (recurse) in everything inside /vob/project. search.run for x in `cat search.strings` do find /vob/project -type f -print | xargs grep -i $x > ~/$x.txt done search.string hello whoami I am getting the error ... (5 Replies)
Discussion started by: siva_jm
5 Replies
Login or Register to Ask a Question