command line - how to find a word in text files from a directory - Ask Ubuntu:
If you don't want to install additional software, you can simply use grep in the terminal.
To recursively search through directories, you can use the -r option (see man grep for details).
The syntax you are looking for is probably:
grep -r "[STRING TO SEARCH FOR]" "[DIRECTORY TO SEARCH]"
So, for instance if I want to search for the string "asdf" in all files in all subdirectories of "/tmp/testdir/" the command looks like this:
grep -r "asdf" "/tmp/testdir/"
The quotation marks are not strictly necessary, but if your string or directory path contains whitespaces, you otherwise would have to mask them using the \ character...
If you don't want to install additional software, you can simply use grep in the terminal.
To recursively search through directories, you can use the -r option (see man grep for details).
The syntax you are looking for is probably:
grep -r "[STRING TO SEARCH FOR]" "[DIRECTORY TO SEARCH]"
So, for instance if I want to search for the string "asdf" in all files in all subdirectories of "/tmp/testdir/" the command looks like this:
grep -r "asdf" "/tmp/testdir/"
The quotation marks are not strictly necessary, but if your string or directory path contains whitespaces, you otherwise would have to mask them using the \ character...
No comments:
Post a Comment