0

I am running the command: ps -ef | grep [p]ts/1

The result is:

root 13820 1733 0 14:19 ? 00:00:00 sshd: root@pts/1 root 13822 13820 0 14:19 pts/1 00:00:00 -bash root 15847 13822 0 15:32 pts/1 00:00:00 ps -ef root 15848 13822 0 15:32 pts/1 00:00:00 grep [p]ts/1

Why is it returning grep and ps?

P.S. Single and double quotes give me the same results. I am able get output without "grep" using grep -v grep works, but I want to use more elegant way.

user5870571
  • 3,094
  • 2
  • 12
  • 35
Iulian
  • 3
  • 2

1 Answers1

1

grep just shows lines matching the regular expression you give it.

Each of the output lines you show does actually have the text "pts/1" on it, perhaps just not where you expected it to be, namely in the controlling tty column on those "unexpected" lines.

As thrig's comment says, you're probably better off with pgrep.

wurtel
  • 3,864
  • 12
  • 15
  • This really should work as the OP expects and generally does https://unix.stackexchange.com/questions/74185/how-can-i-prevent-grep-from-showing-up-in-ps-results – user9517 Mar 15 '17 at 20:16