Linux查找文件并使用grep命令,然后按日期列出。

4

我想查找文件名为formClass.php,并包含checkCookie字符串的文件,并且我想按日期列出文件,显示日期、大小、所有者和组。这些文件位于我的主目录中。

我已经做到了,但它没有显示日期、所有者等信息...

find /home -name formClass.php -exec grep -l "checkCookie" {} \;

我在考虑将"trhg"添加到列表中,像这样,但是没有成功:
find /home -name formClass.php -exec grep -ltrhg "checkCookie" {} \;

谢谢

3个回答

6

尝试运行 find /home -name formClass.php -print0 | xargs -0 grep -l --null checkCookie | xargs -0 ls -l 命令。


2
ls -lt `grep -lr --include=formClass.php "checkCookie" *`

查看man ls以获取其他排序选项。


0

看起来有几种方法可以做到这一点。我找到了这个方法,对我很有效。 find /home -name formClass.php -exec grep -l "checkCookie" {} \; | xargs ls -ltrhg

感谢您提供的其他建议。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接