How to list all the files in a directory and subdirectories that contain a specific text and along the corresponding line in which the text appears in Linux?
How to list all the files in a directory and subdirectories that contain a specific text and along the corresponding line in which the text appears in Linux?
One tool to do this is the grep
command.
The syntax is grep -rin "expressao_procurada"
An example use would be to look for the definition of a function called generate_relatorio in several Python source files.
grep -rin "^def *gerar_relatorio" *.py
The -rin
is for (r) to be recursive, (i) ignore the case and (n) put the line number in the console output.
I did it and it worked: grep -rl "algum-texto" /caminho-do-diretório
.
Where:
-r
option is for you to inform you that you want to search all subdirectories; -l
is for you to inform you that you want to display only the names of the files, instead of the lines of text that match your search I hope I have helped even more!
find /diretorio -exec grep -Fi "texto_especifico" {} \;
The command find
"recursively searches for" directory "all files containing" * specific_text * "searched by grep
.
To list the files, add the option -l
to the command grep
find /diretorio -exec grep -Fil "texto_especifico" {} \;
Friend, you can use the GREP command EX: grep -ri "search_text" / directory. Here is a link that explains how grep works: link
ack regExp diretorio
ack regExp