0
How to list all files in a directory and subdirectories that contain a specific text and together the corresponding line in which the text appears, under Linux?
0
How to list all files in a directory and subdirectories that contain a specific text and together the corresponding line in which the text appears, under Linux?
5
A tool to do this is the command grep
.
The syntax is grep -rin "expressao_procurada"
An example of use would be looking for the definition of a function called gerar_reportario in several Python source files.
grep -rin "^def *gerar_relatorio" *.py
The -rin
is to (r)be recursive, (i)ignore the case and (n) put the line number in the console output.
The parameter -l
is also very useful, makes the grep
print only the list of files that contain the searched text, without including the text line itself. It is a cleaner output, and this list in this format is more suitable to be passed as input from other programs.
3
I did so and it worked: grep -rl "algum-texto" /caminho-do-diretório
.
Where:
-r
serves to inform you that you want to search in all subdirectories;-l
serves to inform you that you want to display only the file names, instead of the text lines that match your searchI hope I’ve been more helpful!
2
find /diretorio -exec grep -Fi "texto_especifico" {} \;
The command find
"search" recursively on "index" all files containing the "*texto_especifico*" searched by grep
.
To list the files add the option -l
in charge grep
find /diretorio -exec grep -Fil "texto_especifico" {} \;
1
ack regExp diretorio
ack regExp
1
Friend, you can use the GREP command EX: grep -ri "texto_da_search" /directory . Here is a link that explains the operation of the grep better: http://blog.glauco.mp/filtragem-de-dados-com-o-comando-grep/
Good answer, but when using links as a response reference always try to place a part of the content of the link :)
OK Silvio! thanks for the tip!
Browser other questions tagged linux filing-cabinet
You are not signed in. Login or sign up in order to post.
Please explain better what you want to do and what you have tried to do What operating system and more details about the problem and the environment. Beyond the expected solution.
– Alexandre Marcondes
Try Ack: http://beyondgrep.com/
– ecdpalma
I changed the question to be more specific.
– Valmir