Issue
I have a Linux server and want to search all the .htaccess files in all the folders (public_html webroot and subfolders) that have a certain word (eg ldap) in it. I also want the file paths returned to these .htaccess files with the word in it and saved to a text file.
Can I do this with grep or find and what syntax is optimal.
I tried find . -type f -printf '"%p"\n' | xargs grep ldap > /tmp/results.txt
but want to only search .htaccess files exclusively.
Thanks
Solution
Following your example, try using:
find . \( -type f -name .htaccess \) -print0 | xargs -0 grep -H ldap > /tmp/results.txt
this find will list null-terminated files .htaccess in . directory, and xargs -0
pass them to the grep. grep -H ldap
will list files containing ldap string with filenames.
Answered By - Maciej Wrobel Answer Checked By - Pedro (WPSolving Volunteer)