linux - 返工查找命令以使用其他扩展

标签 linux shell makefile

我在 Linux 中使用 find 命令时遇到问题。在我的 makefile 中,我有一个变量,我在其中保存所有 .c 代码文件(我在互联网上找到的)

source_files = $(shell find ../src -type f -iname '*.c' | sed 's/^\.\.\/src\///')

但我想添加额外的扩展名 - *.cu 和 *.cpp,而不仅仅是 *.c

例如:

source_files = $(shell find ../src -type f -iname **'*.c;*.cu;*.cpp'** | sed 's/^\.\.\/src\///')

当然我的代码不工作。

如何更改代码以使用其他扩展程序?

最佳答案

您可以在 find 中使用 -o 将搜索条件链接在一起:

source_files = $(shell find ../src -type f -iname '*.c' -o -iname '*.cu' -o -iname '*.cpp' | sed 's/^\.\.\/src\///')

您还可以使用正则表达式搜索:

source_files = $(shell find ../src -type f -regex ".*\.\(c\|cu\|cpp\)$"| sed 's/^\.\.\/src\///')

关于linux - 返工查找命令以使用其他扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26044160/

相关文章:

java - 如何在linux中用包编译java文件

shell - Grails shell 在 Grails 3.0.2 中不起作用?

c++ - 为什么 GNU make 忽略或更改我的 g++ 选项(在命令部分)?

c++ - 使用 epoll 边缘触发时套接字上的数据过多

linux - 更快的方式来agrep?快速找到每个不匹配的字符

shell - Tomcat 即服务

linux - 使用 shell 脚本与程序交互

bash - Makefile bash & xargs 变量不起作用

c - GNU、autotools 的 makefile - 构建 C 语言源代码的规则和方法

mysql - 是否有一个脚本来解析 radius 会计平面文件以导出到单独的 mysql 服务器