linux 查找目录或文件名包含文本的所有文件

linux find all files where directory or filename contains a text

我想查找在文件名或路径中存在给定文本的文件。

例如: find /a/b/ -name "*log*" -type f -or -name "*log*" -type d

(编辑: 看起来 find /a/b/ -name "*log*" 会给出与上面相同的结果。)

以上命令将给出所有包含 log 的目录或文件。结果会是这样的。

/a/b/log      -directory
/a/b/c/log.txt     -file
/a/b/log/log.txt   -file
/a/b/log/xx.txt    -file

但我只想要下面带有文件名的结果,其中日志出现在路径中的任何位置(准确地说,想省略上面结果中的第一行)

/a/b/c/log.txt    
/a/b/log/log.txt
/a/b/log/xx.txt

是否可以在结果中限制为文件,而在搜索条件中限制为文件和目录?

这是你想要的吗:

find /a/b -type f -path "*log*"