Assuming none of your processes is more than 24 hours old,
ps -ef | grep -i my_username | sort +4
will probably suffice
Question
hello guys I am having troubles sorting by date, I have to keep just the newest proccess and kill the older ones
ps -ef | grep -i my_username
then I get let's say 5 or 6 process but I don't know which one is the newest one pls help.
La solution
Assuming none of your processes is more than 24 hours old,
ps -ef | grep -i my_username | sort +4
will probably suffice
Autres conseils
If you are doing this on Linux, this will sort the processes by start time:
ps -ef --sort=start_time
To get the top 5, you can pipe the output to head
:
ps -ef --sort=start_time | head -n 6
I've specified 6 as the top row is a header.
For OS X, this will give you the top 5 oldest processes:
ps aux -O started | head -n 6
If this is Linux, then you can get the start-time of your processes like this:
ps -u your_username -o pid,lstart,cmd
Though, since the lstart
field is date-formatted, I'll admit it's a bit hard to sort on automatically. But if you only have "5 or 6 processes" to care about, then maybe you can just do that manually. :)