# 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 aregrepping all those lines whose name ends withsafeand avoidinggrepitself to be part of the output.The thing here is that if you run the
pscommand andgrepits output, thegrepitself will be listed:So by saying
grep safe\$, or its equivalentgrep "safe$", you are adding a regular expression in the match that will make thegrepitself to not show.As a funny situation, if you use the
-Foption ingrep, it will match exact string, so the only output you will get is thegrepitself: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".