简体   繁体   English

如何查找包含特定文本(包括反斜杠)的所有文件?

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

I thought I found the perfect answer with How do I find all files containing specific text on Linux? 我以为我找到了如何在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? 如何在Linux上查找包含特定文本并包含反斜杠的所有文件?

使用单引号和转义反斜杠。

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

使用单引号。

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

Grep has an option -F to interpret the pattern literally and not as a regular expression. Grep具有-F选项,可以按字面意义而不是正则表达式来解释模式。 For example: 例如:

$ cat infile
use \Concrete\Core\Block\BlockController;
class Controller extends BlockController
$ grep 'Concrete\Core\Block\BlockController' infile     # No match!
$ grep -F 'Concrete\Core\Block\BlockController' infile  # Matches!
use \Concrete\Core\Block\BlockController;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Linux 上查找包含特定文本(字符串)的所有文件? - How to find all files containing specific text (string) on Linux? 如何在 Linux 上找到包含特定文本但不在子目录中的所有文件? - How do I find all files containing specific text on Linux but not in subdirectories? Python - 使用子进程查找目录和子目录中包含特定文本的所有文件 - Python - Find all files containing specific text in directories and subdirectories using subprocess Linux 命令行:在包含特定文本的目录树中查找具有特定扩展名的所有文件 - Linux command line: Find all files with a certain extension in a directory tree containing specific text 如何在 Linux 上查找不包含文本的文本文件? - How to find text files not containing text on Linux? 如何查找包含特定目录的路径的所有文件 - How to find all files which paths contains a specific directories 在Terminal / Linux上查找包含特定日期范围文件名的所有文件 - Find all files containing the filename of specific date range on Terminal/Linux 使用bash,如何查找所有包含特定字符串的文件并将其替换为现有文件? - Using bash, how do I find all files containing a specific string and replace them with an existing file? 如何更改 linux 上包含特定字符串的所有目录/文件的名称 - how to change names of all directories / files containing a specific string on linux 如何查找包含少量特定字符串但不一定在同一行中的所有文件? - How to find all files which include few specific strings but not necessarily in the same line?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM