Finding all files containing a text string on Linux. I came across this solution. H 'text- to- find- here' {} \; (..)Is this close to the proper way to do it? Short answer: Yes, it is very close. Long answer: This command is correct. Using just grep - r (grep - -recursive) is more straightforward: grep 'text- to- find- here' - r < path_to_search> However, your command (combining find and grep) comes in handy sometimes, for example on systems where the grep command doesn't support - r (- -recursive), so let's examine the rest of the question: find / - type f - exec grep - H 'text- to- find- here' {} \; (..)However, it doesn't work. It seems to display every single file in the system. You probably get error messages such asgrep: '< name_of_file_you_do_have_access_to> ': Permission denied. You can avoid these by adding option - s (or - -no- messages) to grep. But then you still get errors likefind: '< name_of_file_you_do_have_access_to> ': Permission denied. To avoid this, you can add 2> /dev/null at the end of your command, to discard all error messages, which gives: find / - type f - exec grep - s.
H 'text- to- find- here' {} \; 2> /dev/null. Finding all files containing a text string on Linux. Which is is why I just find all the file types I'm interested in to begin with. Best way to find the numeric value in UNIX file system. 8. What's the unix command/or perl codes to find files that contains a string, '..'. Find file that contains. find some more information about unix find command at http://scripterworld.blogspot.com/2009/07.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
October 2016
Categories |