2

When we run top command and If we type "T", it will sort based on the TIME+

I want to sort by "TIME+" in command line, using top -n 1

so that I can capture all the process in a file and analyse it one by one.

Note: It is CentOs

4
top -n 1 -b | tail -n +7 | sort  -k 11Vb
  • top -n 1 -b : -b to avoid highlighting chars
  • tail -n +7 : to skip the headers written by top
  • sort -k 11Vb : sort by the 11.th field, skipping white spaces, in a "version" sort mode

Use -k 11Vbr to have reverse order.

  • Excellent works in Centos. – Mani Feb 10 '17 at 6:18
2
$ top -o TIME+ -n 1 >top.out

The -o option is use to select which column to sort on, -n 1 will make top only update once before exiting.

  • @JJoao top on both OpenBSD and Ubuntu has -o. – Kusalananda Feb 9 '17 at 14:49
  • Kusalananda, you are right: after updating my debian top I also have -o!! – JJoao Feb 9 '17 at 14:59
  • My server is Centos, It is not working in centos. My Desktop is ubuntu, so it works. I want it in Centos. – Mani Feb 10 '17 at 6:17
  • @Mani, I had a similar issue: the top's option -o was introduced "recently": in the next update of your server it will probably work fine. Centos and servers in general tent to be conservative. – JJoao Feb 10 '17 at 6:29
  • @Mani CentOS 7.0 seems to also support the -o flag. Maybe it's time to upgrade? unix.com/man-page/centos/1/top – Kusalananda Feb 10 '17 at 7:36

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.