^
and $
can be combined to match an entire line.
For example, the following regex will match a line that starts with the
#
character and ends with the .
character, with any
number of other characters in-between:
$ grep '^#.*\.$' /etc/fstab
# /etc/fstab: static file system information.
In the above example, we surrounded our regular expression with single
quotes to prevent $
from being interpreted by the shell. Without
the single quotes, the $
will disappear from our regex before grep
even has a chance to take a look at it.