linux - 组合查找命令条件

标签 linux unix find

我正在尝试组合 2 个查找命令以通过管道传输到 grep 模式匹配。

我的 3 个命令是:

获取最近 24 小时内修改过的文件:

find '/logs' -mtime 0 -type f

忽略几个目录:

find -type d \( -path /dir -o -path /dir2 -o -path /dir3 \) -prune -o -print

在文件行中查找模式:

grep -rnw -e "my pattern"

我已经开始工作,但似乎无法将目录跳跃添加到组合中。

获取过去 24 小时内修改过的文件并在文件行中查找模式:

find '/logs' -mtime 0 -type f | xargs grep -rnwI -e "my pattern"

因此,理想情况下,我想将过去 24 小时内修改的文件与忽略目录结合起来。

最佳答案

find '/logs' ! -path "*/dir1/*" ! -path "*/dir2/*" ! -path "*/dir3/* -mtime 0 -type f | xargs grep -rnwI -e "my pattern"

find '/logs' -mtime 0 -type f | egrep -v "dir1|dir2|dir3" | xargs grep -rnwI -e "my pattern"

关于linux - 组合查找命令条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41487699/

相关文章:

linux - 更改 Firefox 扩展目录

linux - 退出后如何重新进入docker容器提示符

c - Linux:用负 pid 杀死

php glob 与 scandir

linux - 递归查找并复制到其他目录

linux - 在 Bash 中,我如何获取某个日期的用户输入,然后搜索为该日期创建的文件?

linux - 如何使用特殊字符在中间显示 "grep"文本

linux - 使用 Bash 将标准输入重定向到来自不同的终端

c - 如何读取加载程序中的自定义部分?

linux - 如何 "find all xml files in multiple directories (textfile) and delete"