Search code examples
bashls

grep ls output across tabs


If I ls -l in a directory and get:

-rwxr-x---  1 user1  admin        0  8 Aug  2012 file.txt
-rwxr-x---  1 user1  admin  1733480 26 Jul  2012 Archive.pax.gz
drwxr-x---@ 7 user1  admin      238 31 Jul  2012 Mac Shots
-rwxr-x---@ 1 user3  admin   598445 31 Jul  2012 Mac Shots.zip
-rwxr-x---@ 1 user1  admin      380  6 Jul  2012 an.sh
-rwxr-x---  1 user2  admin       14 30 Jun  2012 analystName.txt
-rwxr-x---  1 user1  admin       36  8 Aug  2012 apple.txt
drwxr-x---@ 7 user1  admin      238 31 Jul  2012 iPad Shots
-rwxr-x---@ 1 user1  admin  7372367 31 Jul  2012 iPad Shots.zip
-rwxr-x---  1 user2  admin      109 30 Jun  2012 test.txt
drwxr-x---  3 user1  admin      102 26 Jul  2012 usr

but want to list only the files owned by "user1" which were modified in "Aug" to get

-rwxr-x---  1 user1  admin        0  8 Aug  2012 file.txt
-rwxr-x---  1 user1  admin       36  8 Aug  2012 apple.txt

What is the best method?


Solution

  • Or you can be more explicit, since Michael's grep would also find a file owned by user1 namedd 'August iPad Shots' no matter when it was modified:

    ls -l | awk '($3=="user1" && $7=="Aug")'