我在 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/