unix中的搜索字符串
我想显示包含字符串CHAR*getenv的所有文件名,其中getenv是一个函数。 我正在使用这个查询unix中的搜索字符串,unix,command,find,Unix,Command,Find,我想显示包含字符串CHAR*getenv的所有文件名,其中getenv是一个函数。 我正在使用这个查询 find . -type f -exec grep -l "CHAR * getenv" {} \; 但它并没有给出期望的输出。它使用字符串CHAR getenv而不是CHAR*getenv显示文件名。使用grep-F防止搜索字符串被视为正则表达式 find . -type f -exec grep -lF "CHAR * getenv" {} \; 或 您需要对*进行转义,因为它意味着0
find . -type f -exec grep -l "CHAR * getenv" {} \;
但它并没有给出期望的输出。它使用字符串CHAR getenv而不是CHAR*getenv显示文件名。使用grep-F防止搜索字符串被视为正则表达式
find . -type f -exec grep -lF "CHAR * getenv" {} \;
或
您需要对*进行转义,因为它意味着0个或多个正在进行的字符(在本例中是空格)问题是bash扩展发生在grep命令执行之前:因此您的行被转换为
find-类型f-exec grep-l CHAR smt getenv{}\;找到-类型f-exec grep-l CHAR smt2 getenv{}\代码>
用单引号替换双引号应该可以解决这个问题,因为这样bash扩展就不会发生
find . -type f -exec grep -l "CHAR \* getenv" {} \;
grep -rl "CHAR \* getenv" *