ps and docker images

Many docker images provide stripped down versions of ps that have almost no options. Normally, it truncates the output to the size of the terminal. Have you ever wondered how to see the entirety of a long command?

The answer is simple: convince ps that you aren’t using a tty and then it won’t truncate:

:; ps | cat

When you pipe it to cat, ps doesn’t think that it’s attached to a tty and so there is no truncation. This trick works for many other commands in different ways, e.g. if you pipe ls to cat, then it only gives you a single column.

Written on September 16, 2022