我试图找到属于特定用户的文件,该文件还包含特定的文本字符串.
例如,我想找到一个属于root用户的文件,并包含“hello there”文本.
grep -irl "hello there" /directory1
find -user root -name "*.txt"
有没有办法可以将这两个命令结合起来?
解决方法:
find -user root -name "*.txt" -exec grep -il "hello there" {} +
find -user root -name "*.txt" -exec grep -iq "hello there" {} \; -print
(-exec可以像-user或-name一样用作测试.如果命令成功,则-exec测试通过并调用-print.)