210

when I run ps -aux command on my linux server, to which I connected using putty, few processes are too long to fit in my current window width. Is there an alternative?

-- Update --

I am sorry for downgrading,I thought others won't find the answer useful too, so I downgraded.

Here is the info you asked for.

hadoop-user@hadoop-desk:~$ echo $TERM
xterm

hadoop-user@hadoop-desk:~$ stty -a
speed 38400 baud; rows 47; columns 158; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke

hadoop-user@hadoop-desk:~$ echo $COLUMNS
158
tshepang
  • 12,111
  • 21
  • 91
  • 136
Boolean
  • 14,266
  • 30
  • 88
  • 129
  • 1
    As an aside, you have provided very little information, so you shouldn't go about downvoting all the answers you've got so far. We are trying to help you. You should post the output of `echo $TERM`, `stty -a`, and `echo $COLUMNS` in your question. – Alok Singhal Jan 29 '10 at 05:18
  • Try `stty ocrnl` and/or `stty sane`? – Alok Singhal Jan 29 '10 at 05:38
  • 46
    `ps axuww` That's the answer ;) At least for me. The doubled `ww` did it. – brutuscat Jan 30 '12 at 19:35

13 Answers13

200

Using the auxww flags, you will see the full path to output in both your terminal window and from shell scripts.

darragh@darraghserver ~ $uname -a
SunOS darraghserver 5.10 Generic_142901-13 i86pc i386 i86pc

darragh@darraghserver ~ $which ps
/usr/bin/ps<br>

darragh@darraghserver ~ $/usr/ucb/ps auxww | grep ps
darragh 13680  0.0  0.0 3872 3152 pts/1    O 14:39:32  0:00 /usr/ucb/ps -auxww
darragh 13681  0.0  0.0 1420  852 pts/1    S 14:39:32  0:00 grep ps

ps aux lists all processes executed by all users. See man ps for details. The ww flag sets unlimited width.

-w         Wide output. Use this option twice for unlimited width.
w          Wide output. Use this option twice for unlimited width.

I found the answer on the following blog:
http://www.snowfrog.net/2010/06/10/solaris-ps-output-truncated-at-80-columns/

Avindra Goolcharan
  • 4,032
  • 3
  • 41
  • 39
darraghmurphy
  • 2,095
  • 1
  • 12
  • 5
168

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.

Dennis Williamson
  • 346,391
  • 90
  • 374
  • 439
  • 23
    Please note that in Linux there is still a limit of 4096 characters hard-coded in kernel code: see http://stackoverflow.com/questions/199130/how-do-i-increase-the-proc-pid-cmdline-4096-byte-limit – Mariano Paniga Dec 13 '13 at 14:00
  • @DennisWilliamson Your statement about `w` not being needed when using a pipe seems to be system-dependent. On both openSUSE Leap 15.0 and Ubuntu 18.04, commands like `ps aux | grep ` act on the output of `ps` truncated by the terminal width. – pkeller Jan 21 '19 at 16:44
  • @DennisWilliamson - Why the argument `-S+`? What is the difference between `-S+` and `-w`? – Motivated Jan 28 '19 at 05:12
  • @Motivated: There's no relationship between `-+S` and `-w` for `less` - they are completely different options. If you're asking about the two different pagers, `less` and `most` (completely independent from each other), the option `-+S` for `less` works similarly to the `-w` option for `most` - they both cause long lines to wrap at the edge of the screen instead of being truncated or scrolled. Further explanation for `less`: `-+` "resets the option to its default setting" so `-S` chops long lines and `-+S` wraps them. See [`man less`](https://linux.die.net/man/1/less) for more information. – Dennis Williamson Jan 28 '19 at 05:29
  • @DennisWilliamson - Thanks I did read `man less` however don't see the argument `-+S` described. It's limited to `-S`. – Motivated Jan 28 '19 at 05:38
  • @Motivated `-S` is documented in one section and `-+` in another. If you start `less` and enter the two variants it will show what the settings do. It is try that it could be better documented, but you might be able to generalize that adding the plus negates the function of the form without the plus. – Dennis Williamson Jan 28 '19 at 05:43
  • @DennisWilliamson - Thanks. I did a search for the `+` operator and it doesn't find it. If i have understood you correctly when you say `you might be able to generalize that adding the plus negates the function of the form without the plus`, do you mean to say `+` inverses the output of `-S`? – Motivated Jan 28 '19 at 05:46
  • @Motivated: You probably need to escape the plus sign for the search since `+` is a regex operator. I wouldn't say it inverses the output, but it inverts the _meaning_: `-S` == truncate, `-+S` == _don't_ truncate == wrap – Dennis Williamson Jan 28 '19 at 14:08
  • @DennisWilliamson - That makes sense. Thanks. – Motivated Jan 28 '19 at 15:57
  • @DennisWilliamson - Out of curiosity, what does "Followed by one of the command line option letters this will reset the option to its default setting and print a message describing the new setting. (The "-+X" command does the same thing as "-+X" on the command line.) This does not work for string-valued options." mean? For example, what does "reset the option to its default setting refer to"? – Motivated Jan 28 '19 at 16:25
  • @Motivated: One of the main uses of `-+` that comes to mind is to override options set in the `LESS` environment variable. For example, I have `LESS="-iMFXRj4a#1"` exported in my environment. The `i` option there causes `less` to ignore case. If I wanted to override that, I can start `less` with `-+i` and the default (case sensitive searches) is set. I could also issue that from within `less`. If I do so, "Case is significant in searches (press RETURN)" is displayed on the status line. – Dennis Williamson Oct 01 '19 at 21:35
  • less does not truncate lines, it just shows them "to the right", so you must scroll. IIRC the left/right keys do that. – David Balažic Apr 20 '20 at 12:23
  • On a QNAP nas (which is hobbled by busybox and other botched up versions of utilities, also this model has an ARM cpu), I could not determine the command line with any option above. Thankfully, I reattached to the `screen ` session it was running in and I found the command line there in the `screen` screen buffer. lol! – Justin Goldberg May 07 '21 at 18:47
144

simple and perfect:

ps -efww

won't truncate line

theDolphin
  • 1,571
  • 1
  • 10
  • 5
80

Just throw it on cat, which line-wraps automatically

ps aux | cat
yoki
  • 817
  • 6
  • 2
18

Passing it a few ws will ignore the display width.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
15

If you are specifying the output format manually you also need to make sure the args option is last in the list of output fields, otherwise it will be truncated.

ps -A -o args,pid,lstart gives

/usr/lib/postgresql/9.5/bin 29900 Thu May 11 10:41:59 2017
postgres: checkpointer proc 29902 Thu May 11 10:41:59 2017
postgres: writer process    29903 Thu May 11 10:41:59 2017
postgres: wal writer proces 29904 Thu May 11 10:41:59 2017
postgres: autovacuum launch 29905 Thu May 11 10:41:59 2017
postgres: stats collector p 29906 Thu May 11 10:41:59 2017
[kworker/2:0]               30188 Fri May 12 09:20:17 2017
/usr/lib/upower/upowerd     30651 Mon May  8 09:57:58 2017
/usr/sbin/apache2 -k start  31288 Fri May 12 07:35:01 2017
/usr/sbin/apache2 -k start  31289 Fri May 12 07:35:01 2017
/sbin/rpc.statd --no-notify 31635 Mon May  8 09:49:12 2017
/sbin/rpcbind -f -w         31637 Mon May  8 09:49:12 2017
[nfsiod]                    31645 Mon May  8 09:49:12 2017
[kworker/1:0]               31801 Fri May 12 09:49:15 2017
[kworker/u16:0]             32658 Fri May 12 11:00:51 2017

but ps -A -o pid,lstart,args gets you the full command line:

29900 Thu May 11 10:41:59 2017 /usr/lib/postgresql/9.5/bin/postgres -D /tmp/4493-d849-dc76-9215 -p 38103
29902 Thu May 11 10:41:59 2017 postgres: checkpointer process   
29903 Thu May 11 10:41:59 2017 postgres: writer process   
29904 Thu May 11 10:41:59 2017 postgres: wal writer process   
29905 Thu May 11 10:41:59 2017 postgres: autovacuum launcher process   
29906 Thu May 11 10:41:59 2017 postgres: stats collector process   
30188 Fri May 12 09:20:17 2017 [kworker/2:0]
30651 Mon May  8 09:57:58 2017 /usr/lib/upower/upowerd
31288 Fri May 12 07:35:01 2017 /usr/sbin/apache2 -k start
31289 Fri May 12 07:35:01 2017 /usr/sbin/apache2 -k start
31635 Mon May  8 09:49:12 2017 /sbin/rpc.statd --no-notify
31637 Mon May  8 09:49:12 2017 /sbin/rpcbind -f -w
31645 Mon May  8 09:49:12 2017 [nfsiod]
31801 Fri May 12 09:49:15 2017 [kworker/1:0]
32658 Fri May 12 11:00:51 2017 [kworker/u16:0]
dshepherd
  • 4,989
  • 4
  • 39
  • 46
  • > make sure the args option is last in the list of output fields, otherwise it will be truncated. Exactly what I needed. Thank you! – ffledgling Jul 15 '21 at 21:52
9

you can set output format,eg to see only the command and the process id.

ps -eo pid,args

see the man page of ps for more output format. alternatively, you can use the -w or --width n options.

If all else fails, here's another workaround, (just to see your long cmds)

awk '{ split(FILENAME,f,"/") ; printf "%s: %s\n", f[3],$0 }' /proc/[0-9]*/cmdline
ghostdog74
  • 327,991
  • 56
  • 259
  • 343
4

Sorry to be late to the party but just found this solution to the problem.

The lines are truncated because ps insists on using the value of $COLUMNS, even if the output is not the screen at that moment. Which is a bug, IMHO. But easy to work around, just make ps think you have a superwide screen, i.e. set COLUMNS high for the duration of the ps command. An example:

$ ps -edalf                 # truncates lines to screen width
$ COLUMNS=1000 ps -edalf    # wraps lines regardless of screen width

I hope this is still useful to someone. All the other ideas seemed much too complicated :)

2

Evidence for truncation mentioned by others, (a personal example)

foo=$(ps -p 689 -o command); echo "$foo"

COMMAND
/opt/conda/bin/python -m ipykernel_launcher -f /root/.local/share/jupyter/runtime/kernel-5732db1a-d484-4a58-9d67-de6ef5ac721b.json

That ^^ captures that long output in a variable As opposed to

ps -p 689 -o command

COMMAND
/opt/conda/bin/python -m ipykernel_launcher -f /root/.local/share/jupyter/runtim

Since I was trying this from a Docker jupyter notebook, I needed to run this with the bang of course ..

!foo=$(ps -p 689 -o command); echo "$foo"

Surprisingly jupyter notebooks let you execute even that! But glad to help find the offending notebook taking up all my memory =D

HeyWatchThis
  • 21,241
  • 6
  • 33
  • 41
1

If none of the solutions above work, the output of ps isn't your problem. Maybe you need to set putty to wrap long lines?

Otherwise, we need more information.

Alok Singhal
  • 93,253
  • 21
  • 125
  • 158
1

If you grep the command that you are looking for with a pipe from ps aux, it will wrap the text automatically. I used a lot of the other answers on here, but sometimes if you are looking for something specific, it is nice to just use grep and you know that it will wrap lines.

For instance ps aux | grep ffmpeg .

carterh062
  • 190
  • 10
1

I found this answer which is what nailed it for me as none of the above answers worked

https://unix.stackexchange.com/questions/91561/ps-full-command-is-too-long

Basically, the kernel is limiting my cmd line.

Community
  • 1
  • 1
Dean Hiller
  • 19,235
  • 25
  • 129
  • 212
0

None of the above worked for me in a docker container with busybox. What I use is:

$ cat /proc/<PID>/cmdline | tr \\0 ' '
Alex
  • 1,313
  • 14
  • 28