Search string in directory, sub-directories and linux files


I have this string : MY_STRING and I have this directory :

|-MY_STRING      // <- directorio con MY_STRING por nombre
|--MY_FILE.txt   // <- archivo con MY_STRING escrito en el
|-MY_STRING.txt  // <- archivo con MY_STRING por nombre

I would like to be able to search MY_STRING with a command and return something like:


At the moment I have tried with commands more or less like this:

grep -ril "MY_STRING" /
grep -rnw '/'-e "MY_STRING"

But these only return the path of the file:

asked by Jorius 11.11.2016 в 18:00

2 answers



In your specific case, assuming you are in the directory /

find . -name MY_STRING

If you are in another directory, and you want to search from the root

find / -name MY_STRING

If you need wildcards , you have to escape them, so that the shell does not make its own:

find / -name que_empiece_asi\*

If you want to shorten the time, and do not get into other file systems, such as /dev , /sys , /proc , ...

find / -mount -name \*que_contenga_esto\*

If you want a detailed listing

find / -mount -name \*yo_que_se\* -exec ls -l '{}' \;

The manual page will show you all the options: man find . It is a very complete and useful command.


I had not read your question well. What you want is to show you any appearance of MY_STRING, either in the name or in the route.

In that case, you have to chain 2 commands:

find / | fgrep TEXTO

find shows you the contents of all the directories.

fgrep shows you only the lines that contain the characters you indicate.

answered by 11.11.2016 / 18:37

try the find command

If I'm not wrong it would be like this:

find "my string"
answered by 11.11.2016 в 18:05