command line grep * does not work but grep *. works
How come "staff*22" does not show anything while "staff.*22" lists lines that contain staff followed by 22 although any of the lines does not contain "." in them?
$ ls -l | grep "staff*22"
$ ls -l | grep "staff.*22"
drwxrwxr-x 2 kim staff 68 Jan 12 22:23 hihi
drwxrwxrwx 4 kim staff 136 Jan 12 22:29 temp2
drwxrwxrwx 3 kim staff 102 Jan 12 22:41 tes2 4 1 Answer
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' staf22grep "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:
5