65

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?

sdabet
  • 961
  • 2
  • 8
  • 14
  • Not an answer, but if I run ps -f in shrinked terminal emulator, output is wrapped on multiple lines. What terminal are you using? – MatthewRock Sep 14 '15 at 08:43
  • 3
    This could be a duplicate of: http://stackoverflow.com/questions/2159860/viewing-full-output-of-ps-command – Tommy Sep 14 '15 at 08:45
  • @MatthewRock I use PuTTy here, do you think this is specific to it? – sdabet Sep 14 '15 at 08:46
  • @Tonsenson Do we consider duplicates across Stackexchange sites ? Also, shouldn't this question belong to unix.stackexchange.com instead of stackoverflow.com ? – sdabet Sep 14 '15 at 08:46
  • @fiddler - see if the answer from Tonsenson's link helps you. If so, the question should be considered inappropriate - posting your question title into google outputs Tonsenson's link as first result, so answer is easy to find. – MatthewRock Sep 14 '15 at 08:50
  • @MatthewRock thanks for the advice. Fiddler: I don't know. Maybe the question is older than the unix community. But have a look at the link and then we can talk about how we are going to proceed – Tommy Sep 14 '15 at 08:53
  • @Tonsenson Yes, this can definitely be considered a duplicate. – sdabet Sep 14 '15 at 08:56
  • @MatthewRock it is. This site started in mid-2010, IIRC. But we don't consider dupes across sites. Quoting that post in an answer here is perfectly fine by Stack Exchange standards. (Though Tonsenson could have tried to retain formatting.) – muru Sep 14 '15 at 08:56
  • Then it's my bad. Initially I didn't see that answer was posted on SE, and [this article](http://unix.stackexchange.com/help/how-to-ask) and maybe some Meta post I've read convinced me that posts that can be answered by simple google query aren't good questions. – MatthewRock Sep 14 '15 at 08:58
  • @MatthewRock Shall I delete the question, then? – sdabet Sep 14 '15 at 09:00
  • According to muru who's more experienced than me, I'd say no. If the answer from @Tonsenson 's link was helpful, then it'd be probably the best that he undeleted his answer. – MatthewRock Sep 14 '15 at 09:02
  • Or just flag this as duplicate of said question? – Tommy Sep 14 '15 at 09:04
  • 1
    @Tonsenson can't close as a cross-site duplicate. – muru Sep 14 '15 at 09:09
  • @muru Shouldn't all these former linux-related questions somehow moved from stackoverflow.com to unix.stackexchange.com/? – sdabet Sep 14 '15 at 09:27
  • 1
    @fiddler ah, we can't migrate old questions without moderator intervention, and even then it's not recommended: http://meta.stackexchange.com/questions/8004/should-we-migrate-old-questions – muru Sep 14 '15 at 09:31

6 Answers6

71

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.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
schily
  • 18,806
  • 5
  • 38
  • 60
51

For simplicity, try this: ps auxfww

fibonacci
  • 975
  • 8
  • 8
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.)

Tommy
  • 221
  • 1
  • 6
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.

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
cinatic
  • 210
  • 2
  • 4
  • 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 '17 at 08:10
0

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

jesse_b
  • 35,934
  • 12
  • 91
  • 140
Jibeex
  • 101
  • 3
  • You don't want to pass it through `echo` unnecessarily. Notice also that [several](https://unix.stackexchange.com/a/358076/117549) [other](https://unix.stackexchange.com/a/229542/117549) 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 07 '19 at 19:08
0

Or you could do

IFS='$';for line in $(ps axf); do echo $line; done
Paulo Tomé
  • 3,754
  • 6
  • 26
  • 38