Listing files whose contains contain a string, and are of a particular extension?
I believe that the following can be used to locate files that contain the contents 'SomeString' or 'SomeOtherString':
Code:
find /home/username/public_html -type f -print0 | xargs -0 egrep -l 'SomeString|SomeOtherString' Also - can someone help explain details of what piping to xargs does here? I don't understand how this command actually works. |
ls <pathname> | egrep '(php|inc|js)$' | xargs <...etc.(your code)..>
ls -R if you need it to drill down |
Code:
find /home/username/public_html -type f -name '*.php' -o -name '*.inc' -o -name '*.js' -print0 | xargs -0 egrep -l 'SomeString|SomeOtherString' |
When you
run a command then add a "| xargs command2". The results of command1 will be passed to command2, possibly on a line−by−line basis -print0 means null char after file name not newline as we have also given -0 option for xargs. -l means only filename mentioned not matching content within it. egrep means extended pattern in grep (same as grep -E) i suggest find . -type f | grep -i "file_extension_you_want" | egrep -i 'pattern1|pattern2' Though not short , but more lucid. by the way -i means ignore case |
All times are GMT -5. The time now is 10:16 PM. |