ls -l | grep

maelamrani

Member
Joined
Jan 3, 2020
Messages
77
Reaction score
7
Credits
450
Hello,
why when i use ls -l with grep it doesnt show any results but with ls it give me the results

5132
 


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
 
Code:
ls -1 essai-grep/* | grep -E /[Ff]raise | xargs ls -l
 
Last edited:

Members online


Top