gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 08:58:35 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com