Linux 查看 PS 命令的完整输出

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2159860/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 19:44:44  来源:igfitidea点击:

Viewing full output of PS command

linuxbashshellprocess

提问by Boolean

when I run ps -auxcommand 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?

当我ps -aux在使用 putty 连接的 linux 服务器上运行命令时,很少有进程太长而无法适应我当前的窗口宽度。有替代方案吗?

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

采纳答案by Paused until further notice.

It is likely that you're using a pager such as lessor mostsince the output of ps auxis longer than a screenful. If so, the following options will cause (or force) long lines to wrap instead of being truncated.

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

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 moreand pg.

more和总是换行pg

When ps auxis used in a pipe, the woption is unnecessary since psonly uses screen width when output is to the terminal.

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

回答by ghostdog74

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

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

ps -eo pid,args

see the man page of ps for more output format. alternatively, you can use the -wor --width noptions.

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

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

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

awk '{ split(FILENAME,f,"/") ; printf "%s: %s\n", f[3],
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
}' /proc/[0-9]*/cmdline

回答by Ignacio Vazquez-Abrams

Passing it a few ws will ignore the display width.

传递几个ws 将忽略显示宽度。

回答by Alok Singhal

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

如果上述解决方案ps均无效,则输出不是您的问题。也许你需要设置腻子来包裹长行

Otherwise, we need more information.

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

回答by darraghmurphy

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

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

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

ps auxlists all processes executed by all users. See man psfor details. The wwflag sets unlimited width.

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

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

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

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

回答by user1932577

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 坚持使用 $COLUMNS 的值,即使当时输出不是屏幕。这是一个错误,恕我直言。但是很容易解决,只要让 ps 认为你有一个超宽的屏幕,即在 ps 命令的持续时间内将 COLUMNS 设置为高。一个例子:

ps -efww

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

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

回答by theDolphin

simple and perfect:

简单而完美:

ps aux | cat

won't truncate line

不会截断行

回答by yoki

Just throw it on cat, which line-wraps automatically

把它扔在 cat 上,它会自动换行

##代码##

回答by carterh062

If you grepthe 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 grepand you know that it will wrap lines.

如果您grep使用来自 ps aux 的管道查找您要查找的命令,它将自动包装文本。我在这里使用了很多其他答案,但有时如果您正在寻找特定的东西,那么使用它很好,grep并且您知道它会换行。

For instance ps aux | grep ffmpeg.

例如ps aux | grep ffmpeg

回答by Dean Hiller

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

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

Basically, the kernel is limiting my cmd line.

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