简体   繁体   English

Linux 查找文件和 grep 然后按日期列出

[英]Linux find files and grep then list by date

I'm trying to find files with the name of formClass.php that contain a string of checkCookie and I want to list the files by date showing the date, size, owner and the group.我正在尝试查找名称为formClass.php的文件,其中包含一个checkCookie字符串,我想按日期列出文件,显示日期、大小、所有者和组。 The files are in my home directory.这些文件在我的主目录中。

I have this working, but it doesn't show date, owner, etc...我有这个工作,但它不显示日期,所有者等......

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

I was thinking that I could add "trhg" to the list like this, but it didn't work:我在想我可以像这样将“trhg”添加到列表中,但它不起作用:

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

Thanks谢谢

Try find /home -name formClass.php -print0 | xargs -0 grep -l --null checkCookie | xargs -0 ls -l尝试find /home -name formClass.php -print0 | xargs -0 grep -l --null checkCookie | xargs -0 ls -l find /home -name formClass.php -print0 | xargs -0 grep -l --null checkCookie | xargs -0 ls -l

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

Take a look at man ls for another sorting options.查看man ls以获取其他排序选项。

It seems there are a few ways to do this.似乎有几种方法可以做到这一点。 I found this and it worked for me.我发现了这个,它对我有用。 find /home -name formClass.php -exec grep -l "checkCookie" {} \;查找 /home -name formClass.php -exec grep -l "checkCookie" {} \; | | xargs ls -ltrhg xargs ls -ltrhg

thank you for the other suggestions.谢谢你的其他建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM