Detecting pattern at the end of a line with grep
If i do.
$ ls -R
.:
4Shared/ Cloud/
./4Shared:
UFAIZLV2R7.part3.rar
./Cloud:
UFAIZLV2R7.part2.rar.part
UFAIZLV2R7.part1.rar.part
UFAIZLV2R7.part4.rar.part
If I want to list the .rar
files only, and I use grep, it will show me too the .rar.part
files, what is not my wish.
I am solving this using find
or ls **/*.rar
as told in this thread and they work fine, but I would like to learn if it is possible to do it via grep
.
I have tried (thinking about EOL
).
ls -R | grep ".rar\n"
with no results.
I think that the problem lies in discover if the greping is found at the end of the line, but I am not sure.
Is there any help here please?
Best Answer
The $
anchor matches the end of a line.
ls -R | grep '\.rar$'
You can also use find
for this.
find . -name '*.rar'