user1032531 user1032531 - 2 months ago 9
Linux Question

How to find all files containing specific text (which includes a backslash)?

I thought I found the perfect answer with How to find all files containing specific text on Linux?, so I tried it:

[Michael@devserver ~]$ grep -rnw '/var/www/concrete5.7.5.9/' -e "Concrete\Core\Block\BlockController"
[Michael@devserver ~]$


None show, but I know there should have been a match.

[Michael@devserver ~]$ grep -rnw '/var/www/concrete5.7.5.9/concrete/blocks/html' -e "BlockController"
/var/www/concrete5.7.5.9/concrete/blocks/html/controller.php:5:use \Concrete\Core\Block\BlockController;
/var/www/concrete5.7.5.9/concrete/blocks/html/controller.php:7:class Controller extends BlockController
[Michael@devserver ~]$


I also tried escaping the backslash to no avail.

[Michael@devserver ~]$ grep -rnw '/var/www/concrete5.7.5.9/' -e "Concrete\\Core\\Block\\BlockController"
[Michael@devserver ~]$


Also tried single quotes to no avail.

[Michael@devserver ~]$ grep -rnw '/var/www/concrete5.7.5.9/' -e 'Concrete\Core\Block\BlockController'
[Michael@devserver ~]$


How to find all files containing specific text which includes a backslash on Linux?

Answer

Use single quotes and escape backslash.

grep -rnw '/var/www/concrete5.7.5.9/' -e'Concrete\\Core\\Block\\BlockController'