However, you can set the screen width like this to truncate the output (but it won't override -w):
ps ax --width=80
You can also use the o (or -o or --format) option to include only columns that you are interested in, change or eliminate column headers and set the width of each column individually*. See man ps and search for "user-defined format" (multiple occurrences).
* setting a column width smaller than normal may change the way the contents or displayed or may not have an affect. For example, "args:20" doesn't truncate the output (unless it's not the last column) and "user:5" causes usernames longer than five characters to be displayed as the UID number.
I am not able to comment on Dennis Williamson's answer (maybe I have too few points for that); that's why I am writing a new answer.
You can do
ps ax --width=$COLUMNS
to get the output width adjusted according to the current terminal size. If your
favorite shell does not support COLUMNS environmental variable, you can use stty:
ps ax --width=$(stty -a | grep 'columns [0-9]*;' | sed 's|.*columns \([0-9]*\).*|\1|')
or more specifically (using single awk but making stronger assumption on the
stty -a output format):
All this is quite a bit of typing, so you might want to consider making the
above an alias or a shell function... :-) The above maybe needs to be adjusted
for your operating system (I cannot test now, I am not using OS X but Linux).
I have the following output for stty -a:
For me,
ps
doesn't wrap unless I do:However, you can set the screen width like this to truncate the output (but it won't override
-w
):You can also use the
o
(or-o
or--format
) option to include only columns that you are interested in, change or eliminate column headers and set the width of each column individually*. Seeman ps
and search for "user-defined format" (multiple occurrences).*
setting a column width smaller than normal may change the way the contents or displayed or may not have an affect. For example, "args:20" doesn't truncate the output (unless it's not the last column) and "user:5" causes usernames longer than five characters to be displayed as the UID number.I am not able to comment on Dennis Williamson's answer (maybe I have too few points for that); that's why I am writing a new answer.
You can do
to get the output width adjusted according to the current terminal size. If your favorite shell does not support COLUMNS environmental variable, you can use stty:
or more specifically (using single awk but making stronger assumption on the stty -a output format):
All this is quite a bit of typing, so you might want to consider making the above an alias or a shell function... :-) The above maybe needs to be adjusted for your operating system (I cannot test now, I am not using OS X but Linux). I have the following output for stty -a:
Appending
less -S
at the end of any command would unwrap the command output on Linux terminal.Example: 1 (Your original command appended with
less -S
)Example: 2. Even better, next command reveals % CPU and Memory consumption of each Java thread/Process ID.
It's true for any generic process:
PS: For Linux 6.x or higher,
grep -E
can be used instead ofegrep