How to list files in a directory and subdirectories that contain a specific text in Linux? [closed]

0

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?

    
asked by anonymous 29.01.2014 / 20:32

5 answers

5

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.

    
29.01.2014 / 20:32
3

I did it and it worked: grep -rl "algum-texto" /caminho-do-diretório .

Where:

  • the -r option is for you to inform you that you want to search all subdirectories;
  • option -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!

    
19.02.2014 / 07:06
2
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" {} \;
    
03.02.2014 / 13:27
1

Friend, you can use the GREP command EX: grep -ri "search_text" / directory. Here is a link that explains how grep works: link

    
23.05.2014 / 16:34
1
ack  regExp  diretorio
ack  regExp
    
05.10.2015 / 17:37