What do given grep commands do
From your output it is apparent that you want to find all files that belong to "staff" group and created at hour 22 ( or 10 pm in 12 hour format ). We'll address that below, but lets first figure out what your grep
commands do and why they're not the right tool for what you want.
First of all, the two grep
commands that you do are slightly different in the way they are interpreted, and your approach is not proper - you shouldn't try to parse output of ls.
grep "staff*22"
reads as "match all lines that start with 'staf' and may or may not have in them extra 'f' , immediately followed by '22'."
$ echo "staff whatever 22" | grep 'staff*22'
$ echo "staff22" | grep 'staf*22'
staff22
$ echo "staf22" | grep 'staff*22'
staf22
$ echo "staf22" | grep 'staff*22'
staf22
grep "staff.*22"
reads as "match all lines that have 'staff' in them, zero or more characters in between ( any type of character ),and number 22".
$ echo "staff whatever 22" | grep 'staff.*22'
staff whatever 22
Better approach
ls
command in general should only be used for interactive listing, i.e., when you only want to have a quick peek at what's inside a folder. When it is necessary to find specific files, or some how work with those files via script, find
command is the way to go. It has -group
variable, which will help you isolate all the files that belong to staff
group, and -nevermt
for finding files with modification time newer than some specific date. For instance, what you want is probably this:
find . -group staff -newermt "2017-01-12 21:59:59"
See also this: https://superuser.com/questions/580273/ubuntu-linux-find-files-between-specific-times
man grep
and see the details about regular expressions and.
=[^\n]
= any char except newline.staff
group and end with number 2 in filename ?