Help with BASH to search text files on disk
Hello guys,
M new to bash scripting and i wish to search all text files present on local disk. But m unable to write correct script for it. Please help me.... |
It's worth having a look at the advanced bash scripting guide - it's a very useful document.
You can use grep to do what you want and you can call it a couple of ways. If you just want to search for a string in every single file: Code:
grep -r 'search-string' /* Code:
find / -type f -name '*java' -exec grep 'search-string' {} \; |
usually I use:
find <dir> -exec grep -l {} \; the -l option to grep makes that grep only returns the filename and not the line it found in the file. If you don't use this option, you have all these lines, but you don't know which file it comes from. |
Don't forget that if you're searching for a fixed string, rather than a regex, the grep "-F" can speed things up a lot.
BTW, gilead, that is a very thoughtful warning, thanks. :) |
concerning "grep -r", i would use "grep -Ir" to ignore binary files.
|
I have this
Code:
alias search='find . \! -iname '\''*~'\'' -print |xargs grep -s --ignore-case --binary-files=without-match --line-number' Code:
search searchterm |
All times are GMT -5. The time now is 09:17 AM. |