66

When running ps with the -f option in PuTTY (to see the command corresponding to each process), lines which are longer than the terminal width are not fully visible (they are not wrapped on multiple lines).

How can I force line wrapping so that I can see the full commands (on multiple lines, if necessary) when running ps -f?

15
  • Not an answer, but if I run ps -f in shrinked terminal emulator, output is wrapped on multiple lines. What terminal are you using? Sep 14, 2015 at 8:43
  • 3
    This could be a duplicate of: stackoverflow.com/questions/2159860/…
    – Tommy
    Sep 14, 2015 at 8:45
  • @MatthewRock I use PuTTy here, do you think this is specific to it?
    – sdabet
    Sep 14, 2015 at 8:46
  • 1
    @Tonsenson can't close as a cross-site duplicate.
    – muru
    Sep 14, 2015 at 9:09
  • 1
    @fiddler ah, we can't migrate old questions without moderator intervention, and even then it's not recommended: meta.stackexchange.com/questions/8004/…
    – muru
    Sep 14, 2015 at 9:31

6 Answers 6

73

If you have a POSIX-conforming ps implementation, you may try

ps -f | more

Note that we¹ recently changed the behavior and if you have an implementation that follows POSIX issue 7 tc2, you may try:

ps -wwf | more

¹ We being the people who have weekly teleconferences to discuss the evolvement of the POSIX standard.

2
  • 4
    ps -wwf works just fine.
    – sdabet
    Sep 14, 2015 at 9:28
  • Note, this is the right answer for the questioner's case (ps -f), but others may prefer having aux in there as well, as in fibonacci's answer.
    – mwfearnley
    Nov 2, 2022 at 12:07
54

For simplicity, try this: ps auxfww

3
  • 2
    This worked! The accepted answer (of ps -wwf and ps -f) did not. Aug 29, 2021 at 4:50
  • not working for me Jun 3, 2022 at 10:24
  • Worked for me, I'm guessing it's because I'm on PowerShell and not on a putty or ssh terminal. Oct 19, 2022 at 12:47
12

I've probably found the answer for your question on Stack Overflow. In the words of Dennis Williamson:

It is likely that you're using a pager such as less or most since the output of ps aux is longer than a screenful. If so, the following options will cause (or force) long lines to wrap instead of being truncated.

ps aux | less -+S

ps aux | most -w If you use either of the following commands, lines won't be wrapped but you can use your arrow keys or other movement keys to scroll left and right.

ps aux | less -S # use arrow keys, or Esc+( and Esc+), or Alt+( and Alt+)

ps aux | most # use arrow keys, or < and > (Tab can also be used to scroll right) Lines are always wrapped for more and pg.

When ps aux is used in a pipe, the w option is unnecessary since ps only uses screen width when output is to the terminal.

(Note: this applies to non-embedded Linux, the ps utility on other Unix variants may work differently.)

7
  • @muru hope this is now looking better. Thanks for clearing all up!
    – Tommy
    Sep 14, 2015 at 9:28
  • And sorry for causing the mess. Sep 14, 2015 at 9:28
  • 1
    Your answer only applies to /usr/ucb/ps and even with this program you would need ww as /usr/ucb/ps limits the output width to 80 if the output is a pipe. For the POSIX standard ps, see my answer.
    – schily
    Sep 14, 2015 at 11:49
  • 1
    @schily This answer is perfectly correct for the usual ps command on non-embedded Linux, which is what a majority of readers here have. Sep 14, 2015 at 20:57
  • 1
    But the OP did not set /linux as tag.
    – schily
    Sep 14, 2015 at 22:13
7

There is also another simple solution:

echo "$(ps afx)"

When run in a command substitution like this, ps isn’t sending its output to a terminal, so it doesn’t limit its output to the terminal’s width.

1
  • 1
    Thanks for that. Now, the command behaves completely differently on MacOS (I hear its based on BSD) and Ubuntu (Linux). Linux isn't showing any difference in when u echo or not. But, MAC OS X is printing as much as the terminal can show. I'm using iTerm2 and zsh. MAC doesn't allow the --f option.
    – nyxee
    Feb 22, 2017 at 8:10
0

The command for MacOS is slightly different echo "$(ps aux)"

1
  • You don't want to pass it through echo unnecessarily. Notice also that several other answers already mention ps aux in some way. I would suggest comments or edits on those existing answers to point out that they're good for MacOS (which is what I assume you meant).
    – Jeff Schaller
    Jun 7, 2019 at 19:08
0

Or you could do

IFS='$';for line in $(ps axf); do echo $line; done
1
  • I am curious, why are you setting IFS to $?
    – AdminBee
    Feb 20, 2020 at 13:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .