Search code examples
unixsortingps

Sorting results of ps by start time


I'm displaying information about the current processes using this variety of the ps command:

ps -eo pid,start,stime,command

How can I sort these results by start?

I've read man ps and tried -m, -r and -v sorting options. Unfortunately I haven't been able to use these options to sort by start.


Solution

  • You use etime. That's elapsed time, in days, hours, etc. which is suitable for sorting numerically. If it's the first column, I think ps will sort by it automatically.

    Otherwise, you can override sort order by using --sort, but make sure it is after the -o option, example:

    ps -o pid,user:32,start,etime,state,time,vsz,args --sort=etime