查看PS命令的完整输出

Boo*_*ean 154 linux bash shell process

当我ps -aux在我的linux服务器上运行命令时,我使用putty连接到该命令,很少有进程太长而无法适应我当前的窗口宽度.还有其他选择吗?

- 更新 -

我很抱歉降级,我认为其他人也不会觉得答案有用,所以我降级了.

这是您要求的信息.

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
Run Code Online (Sandbox Code Playgroud)

小智 140

使用auxww标志,您将在终端窗口和shell脚本中看到输出的完整路径.

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
Run Code Online (Sandbox Code Playgroud)

ps aux列出所有用户执行的所有进程.详情man ps请见.该ww标志设置无限宽度.

-w         Wide output. Use this option twice for unlimited width.
w          Wide output. Use this option twice for unlimited width.
Run Code Online (Sandbox Code Playgroud)

我在以下博客上找到了答案:http:
//www.snowfrog.n​​et/2010/06/10/solaris-ps-output-truncated-at-80-columns/

  • 这是比当前接受的解决方案更好的答案,因为并非所有系统(嵌入式Linux)都包含"最多","更多"或"更少"的寻呼机. (10认同)
  • 或者,`ps auxf &gt; ps.log` (2认同)

Pau*_*ce. 134

您可能正在使用寻呼机,例如lessmost因为输出ps aux超过屏幕.如果是这样,以下选项将导致(或强制)长行换行而不是被截断.

ps aux | less -+S

ps aux | most -w
Run Code Online (Sandbox Code Playgroud)

如果使用以下任一命令,则不会包裹线条,但您可以使用箭头键或其他移动键向左和向右滚动.

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)
Run Code Online (Sandbox Code Playgroud)

线总是包裹着morepg.

ps aux在管道中使用时,该w选项是不必要的,因为ps当输出到终端时仅使用屏幕宽度.

  • 请注意,在Linux中,内核代码中仍有4096个字符的硬编码限制:请参阅http://stackoverflow.com/questions/199130/how-do-i-increase-the-proc-pid-cmdline-4096字节限制 (19认同)
  • @MarianoPaniga:你用这个评论救了我的命. (3认同)

the*_*hin 104

简单而完美:

ps -efww
Run Code Online (Sandbox Code Playgroud)

不会截断行

  • 这是负责完整输出的“ ww”部分” (2认同)

小智 56

把它扔到猫身上,自动换行

ps aux | cat
Run Code Online (Sandbox Code Playgroud)

  • 像BusyBox这样的轻量级Linux发行版的良好解决方案,其中高级工具不可用:) (8认同)

Ign*_*ams 15

传递几秒w将忽略显示宽度.


dsh*_*erd 8

如果要手动指定输出格式,还需要确保该args选项在输出字段列表中位于最后,否则将被截断.

ps -A -o args,pid,lstart

/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
Run Code Online (Sandbox Code Playgroud)

但是ps -A -o pid,lstart,args获取完整的命令行:

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]
Run Code Online (Sandbox Code Playgroud)


gho*_*g74 7

您可以设置输出格式,例如,仅查看命令和进程ID.

ps -eo pid,args
Run Code Online (Sandbox Code Playgroud)

有关更多输出格式,请参阅ps的手册页.或者,您可以使用-w--width n选项.

如果所有其他方法都失败了,这是另一种解决方法,(只是为了查看你的长cmds)

awk '{ split(FILENAME,f,"/") ; printf "%s: %s\n", f[3],$0 }' /proc/[0-9]*/cmdline
Run Code Online (Sandbox Code Playgroud)