1

I need to find all running processes whose owner is neither root nor Student. I know how to not get running processes whose owner is neither root nor Student by type

ps aux | egrep '^[^(root)|(Student)]'

I am struggling with get all running processes that aren't Student or root. Right now, I only get some running processes by typing

ps aux | egrep '^[^(root)|(Student)]'

I tried [a-z]+ and it shows root and other running processes. How to get all running process without root and Student using egrep?

Lenin
  • 661
  • 5
  • 9
Rikki
  • 11
  • 2

1 Answers1

1

ps aux | grep -vE '^(root|Student) '

'[^(root)|(Student)]' would match letters which are not in the class, it's not what we want to achieve. Simply use grep -E (which is the same as egrep) with the regex '^(root|Student) ' (match everything starting by either root or Student and ending in a space) but print everything not matching by using the -v option.

Also note ps lets you custom the columns. For example, if you only wanted the pids you could use ps -eo ruser,pid instead of ps aux. Or you could match by uid using ruid instead of ruser (specially handful if the user name gets truncated).

Ángel
  • 1,393