Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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:

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

Thanks

like image 480
EricP Avatar asked Feb 25 '23 02:02

EricP


2 Answers

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

like image 125
artbristol Avatar answered Feb 26 '23 19:02

artbristol


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

Take a look at man ls for another sorting options.

like image 35
khachik Avatar answered Feb 26 '23 21:02

khachik