How to find a particular string!! from a Directory
Hi all,
I want to search a particular string in a directory , that directory contains N number of subdirectories, and files and my requirement is inside the directory and subdirectory what are the files contains particular string like "TBone" i want to display that files. Is it possible to do that.. Dont think this as a homework, this simple command helps me in lot of ways. so please guide me to solve this thread. |
@ Reply
Hi there,
As I can understand you are trying to look for a filename/directory name that contains a particular string say ABC. I think locate command will work for you. Code:
updatedb /* This command will update the database which locate command will use */ You can use find command to do your job Code:
find / -name *string* |
Is the string in the name of the file or actually inside the file?
As previous post answers part 1 then the answer to part 2 would be to use grep: Code:
grep -r -l string top_dir/* |
Hi grail,
My requirement is inside the file, for example: a directory name Code:
"grail" Code:
anish,txt Quote:
Code:
God Save Me, i love my dad Quote:
Code:
I love My friends Quote:
Quote:
Code:
Who love me? Quote:
Code:
boys.txt |
The grep i provided should be able to help:
Code:
grep -r -l "God Save Me, i love my dad" grail/* |
Hi grail,
command you have given provide only one level search , It doesn't list all the files there. I've tried with the scenario described by anish it gives me following result directory structure [root@master tmp]# ls -R .: grail ./grail: anish.txt boys.txt father jesus linux.txt ./grail/father: ./grail/jesus: questions.txt and command provided by you shows this result [root@master tmp]# grep -i -l "love" grail/* grail/anish.txt [root@master tmp]# cat grail/anish.txt God Save Me,i love my mom I should list all the files containing the word love... thanx samtoddler |
Maybe if you used -r instead of -i, which was my suggestion, you will get the correct result.
|
hi grail,
thanx lil typo... samtoddler |
Hi all,
Thanks for all replies, you guys done a great help for me.. Thank you so much :-) |
All times are GMT -5. The time now is 11:53 PM. |