15

In top screen, by default it shows all users' processes. How to exclude some users(for example, root and nobody) from the top real-time screen?

14

The correct answer is: -U '!root' (or -u '!root' on some Ubuntus). This was introduced in top v3.2.9:

man top for -U option:

Prepending an exclamation point ('!') to the user id or name instructs top to display only processes with users not matching the one provided.

Remember to put the exclamation mark and username in single quotes.

  • 3
    Please note this works on the more recent versions of top. 3.3.9 has it, while 3.2.8 hasn't. – Deer Hunter Sep 4 '14 at 11:52
  • 3
    Oddly enough, on Ubuntu 14.04, I needed to use -u instead of -U. – muru Sep 20 '16 at 21:22
  • 4
    I had to use top -u '!root' to NOT get the ! to be interpreted by the shell (I believe that is what is happening w/o the single quotes). – steveb Dec 30 '16 at 22:09
  • Interactively you can type u and then !root – Dr Beco Apr 12 '17 at 5:22
  • 2
    Better yet, add a filter to exclude all system users, like O and filter RUID>999. You need to add RUID column first. – Dr Beco Apr 12 '17 at 6:00
3

Also, as of version 3.3, you can just type u while top is running and enter that !root string.

2

top -U root shows only processes from root. Unfortunately that is the only option for limiting users according to the man page.

  • But if you wanted to deviate from using top, you could do ps aux | grep -v $USERNAME to see all processes except the user you specified. – Tim Jan 6 '12 at 18:14
  • Thanks. I know those two commands. I've searched around but didn't find anyone ask about this. top -u can see one user, but I want to see more users in real-time. – garconcn Jan 6 '12 at 18:22
  • 4
    top | egrep -ve "(root|knoppix)"? Modify to suit your requirements. – dtbnguyen Jan 7 '12 at 2:52
1

As suggested by Dr Beco above the most general filtering mechanism uses 'o/O' to activate "Other Filtering" while in top to exclude/include more than one user.

For example to exclude "root" and "nobody" one can use the command o!USER=root<enter>o!USER=nobody.

Many interesting views are possible with this filtering option!

  • I think this is the only answer that answers the question: "exclude some users (for example, root and nobody)", i.e. excluding more than one user. Perhaps this wasn't possible in 2012. – Ramashalanka Mar 5 at 22:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.