• Rob's side project: I recently started Gun-Forums.com and we currently have a $100 raffle - if you're into guns, join up and enter the raffle to win $100.00. Gun Forums

ls -l | grep



JasKinasis

Well-Known Member
Hello,
why when i use ls -l with grep it doesnt show any results but with ls it give me the results

View attachment 5132
The reason is because ls and ls -l format their output differently.

Your pattern is matching the start of the line. And because ls only lists the file/directory names - your pattern will work with ls.

However, when you use ls -l, the listing format starts with the permissions, user/group, file-size, time-stamp and the file-name is at the end.
So in this case - rather than matching the start of the line, your pattern needs to match the end of the line instead.
So remove the ^ at the start of the pattern and add $ at the end:
e.g.
ls -l | egrep [Ff]raise$
That should work with ls -l
 


Members online


Top