# ps | grep safe
14592 root 136m S /tmp/data/safe/safe
16210 root 1664 S grep safe
# ps | grep safe\$
14592 root 258m S /tmp/data/safe/safe
So what does \$
mean? Is it a regular expression?
# ps | grep safe
14592 root 136m S /tmp/data/safe/safe
16210 root 1664 S grep safe
# ps | grep safe\$
14592 root 258m S /tmp/data/safe/safe
So what does \$
mean? Is it a regular expression?
Copyright © 2021 Jogjafile Inc.
Yes, it is a regex.
$
is a regex character that means "end of line". So by sayinggrep safe\$
you aregrep
ping all those lines whose name ends withsafe
and avoidinggrep
itself to be part of the output.The thing here is that if you run the
ps
command andgrep
its output, thegrep
itself will be listed:So by saying
grep safe\$
, or its equivalentgrep "safe$"
, you are adding a regular expression in the match that will make thegrep
itself to not show.As a funny situation, if you use the
-F
option ingrep
, it will match exact string, so the only output you will get is thegrep
itself:The typical trick to do this is
grep -v grep
, but you can find others in More elegant "ps aux | grep -v grep". I like the one that saysps -ef | grep "[b]ash"
.