代码之家  ›  专栏  ›  技术社区  ›  Boolean

查看ps命令的完整输出

  •  129
  • Boolean  · 技术社区  · 15 年前

    当我奔跑 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
    
    11 回复  |  直到 6 年前
        1
  •  114
  •   Dennis Williamson    6 年前

    很可能你在使用寻呼机,比如 less most 自从输出 ps aux 比屏幕长。如果是这样,以下选项将导致(或强制)长线换行,而不是被截断。

    ps aux | less -+S
    
    ps aux | most -w
    

    如果使用以下任一命令,行将不会换行,但可以使用箭头键或其他移动键左右滚动。

    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)
    

    行总是换行 more pg .

    什么时候? PS辅助 在管道中使用, w 选项是不必要的,因为 ps 只有当输出到终端时才使用屏幕宽度。

        2
  •  117
  •   Avindra Goolcharan    8 年前

    使用 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
    

    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.
    

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

        3
  •  89
  •   theDolphin    11 年前

    简单完美:

    ps -efww
    

    不会截断行

        4
  •  46
  •   yoki    10 年前

    把它扔到猫身上,哪条线会自动缠绕

    ps aux | cat
    
        5
  •  13
  •   Ignacio Vazquez-Abrams    15 年前

    传了几次 w s将忽略显示宽度。

        6
  •  8
  •   dshepherd    7 年前

    如果要手动指定输出格式,还需要确保 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
    

    但是 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]
    
        7
  •  7
  •   ghostdog74    15 年前

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

    ps -eo pid,args
    

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

    如果其他都失败了,这里还有另一个解决方法(只是看看你的长命令)

    awk '{ split(FILENAME,f,"/") ; printf "%s: %s\n", f[3],$0 }' /proc/[0-9]*/cmdline
    
        8
  •  3
  •   user1932577    12 年前

    很抱歉来晚了,但刚找到解决问题的办法。

    行被截断,因为ps坚持使用$columns的值,即使此时输出不是屏幕。这是个虫子,imho。但工作起来很容易,只要 ps认为您有一个超宽屏幕,即在ps命令期间将列设置为高。一个例子:

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

    我希望这对某人仍然有用。所有其他的想法似乎都太复杂了:)

        9
  •  1
  •   carterh062    8 年前

    如果你 grep 使用ps aux中的管道查找的命令,它将自动换行文本。我在这里用了很多其他的答案,但有时如果你想找一些具体的答案,最好只使用 格雷普 你知道它会把线包起来。

    例如 ps aux | grep ffmpeg .

        10
  •  0
  •   Alok Singhal    15 年前

    如果上述解决方案都不起作用,则输出 ps 这不是你的问题。也许你需要把油灰 wrap long lines ?

    否则,我们需要更多的信息。

        11
  •  0
  •   Community T.Woody    7 年前

    我找到了这个答案,因为上面的答案都不管用

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

    基本上,内核限制了我的命令行。