Sort ‘ps’ by memory usage in Linux

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, January 12, 2016

Follow me on Twitter as @mattiasgeniar

If you type ps aux, you’ll get a detailed output of all linux processes running at that time.

Here’s a little trick that allows you to sort that output by memory consumption, so the biggest memory consumers are at the bottom.

$ ps aux | sort -nk +4 | tail -n 10

This sorts the output of ps by the 4th field (%MEM) and only shows the last 10 lines.

Alternatively, you can also pass the --sort parameter to ps directly. For instance:

$ ps aux --sort -rss | head

This shows the top consumers at the top.



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.