Many times you find yourself at the top of complex directory tree, seeking for a file that contains some specific string value. Nautilus is not very helpful now, as it can only search on file names, not content. It seems that the command line is the only way.
Of course, you can always visit every single subdirectory in the tree and grep all files each time. But this is very inefficient and time consuming as the number of subdirectories grow larger, not to mention the probability of skipping some subdirectories by mistake.
"There must be a better way", you may think. And you are right. This is the command that will do the job for you:
This command will output all the files under /path/to/top/level/directory that contain the stringl [neede]. The ; at the end is necessary to denote the end of the command. Make sure that you use appropriate escaping (\) according to your shell's fads.
If you are a Windows user and you cannot search within your files' contents (that's ok, it's not your fault, it's just that bloody windows explorer that never functioned...), you can also use the solution described here, at the cost of installing GNU utilities for Win32.
Of course, you can always visit every single subdirectory in the tree and grep all files each time. But this is very inefficient and time consuming as the number of subdirectories grow larger, not to mention the probability of skipping some subdirectories by mistake.
"There must be a better way", you may think. And you are right. This is the command that will do the job for you:
find /path/to/top/level/directory -type f -exec grep -F -H [needle] {} \;This command will output all the files under /path/to/top/level/directory that contain the stringl [neede]. The ; at the end is necessary to denote the end of the command. Make sure that you use appropriate escaping (\) according to your shell's fads.
If you are a Windows user and you cannot search within your files' contents (that's ok, it's not your fault, it's just that bloody windows explorer that never functioned...), you can also use the solution described here, at the cost of installing GNU utilities for Win32.
Leave a Reply