当我在我的linux服务器上运行ps -aux命令时,我使用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

当前回答

其他人提到的截断证据(个人例子)

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

^^在变量中捕获长输出 而不是

ps -p 689 -o command

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

因为我试图从一个Docker jupyter笔记本,我需要运行这个当然爆炸..

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

令人惊讶的是,jupyter笔记本甚至可以让你执行!但是很高兴能帮你找到那本占用了我所有内存的笔记本

其他回答

如果上面的解决方案都不起作用,ps的输出不是你的问题。也许你需要设置腻子来包裹长线?

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

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

ps -A -o参数,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]

很抱歉来晚了,但我刚刚找到了这个问题的解决方案。

这些行被截断,因为ps坚持使用$COLUMNS的值,即使输出不是当时的屏幕。恕我直言,这是个bug。但是很容易变通,只要做出来就行了 ps认为你有一个超宽的屏幕,即设置COLUMNS高ps命令的持续时间。一个例子:

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

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

我找到了这个答案,这就是我的答案,因为上面的答案都不奏效

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

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

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