什么是以下&QUOT的语法的简要说明;顶"命令:顶部-p`指派,进程名称| TR" \\\\ N'QUOT; "," | SED的/,$ //'` [英] What is a brief explanation of the syntax of the following "top" command: top -p `pgrep process-name | tr "\\n" "," | sed 's/,$//'`
问题描述
在此之前到今天,尽管有许多不同的Linux命令,我并没有试图了解一些一个有用越来越舒适
Prior to today, despite growing comfort with many and varied Linux commands, I have not attempted to understand some of the components of a useful command from another StackOverflow posting to filter the top
command to certain processes (by process name):
top -p `pgrep process-name | tr "\\n" "," | sed 's/,$//'`
本顶
命令包含各种句法成分。我可以查找每个组件依次(有些是显而易见的,如管道命令 - 虽然我还没有的 100%的舒适与管道之间的区别 |
和重定向方式>
)
This top
command contains various syntactic components. I could look up each component in turn (and some are obvious, such as the pipe command - though I'm still not 100% comfortable with the distinction between the pipe |
and redirection >
).
不过,由于过滤顶
通过进程名称的命令往往是有用的,因为该命令是在表面上显然不是从语法的角度来看微不足道的,这将是有益的我(也许其他人)必须为这一切命令块的实际(简介)说明一个参考,在一个地方。
However, because filtering the top
command by process name is often useful, and because the command is on its face clearly not trivial from a syntax perspective, it would be useful for me (and perhaps others) to have a reference to an actual (brief) explanation for all of the pieces of this command, in one place.
所以,我的问题是下面的。
Therefore, my question is the following.
什么是所有组件的上述上面的简要说明
命令(即过滤顶部的输出
通过进程名称)?我想AP preciate不留一块语法出来,如果连只是简单提一下。谢谢!
What is a brief explanation of all of the components of the above top
command (that filters the output of top
by process name)? I would appreciate leaving no piece of syntax out, if even for just a brief mention. Thanks!
推荐答案
我会尝试在部分回答你的问题进行分解。
I'll try to break it down by answering your question in pieces.
我们来看看第一部分是 SED的/,$ //'
。我不打算要能简单介绍一下 SED
命令,但请看的 GNU sed的手册了解详情。在的/,$ //'
告诉 SED
来寻找任何逗号在一行的末尾,什么也没有替换。这是消除对 SED
的标准输入全部来自各行末尾的逗号。
The first piece we'll look at is sed 's/,$//'
. I'm not going to be able to briefly explain the sed
command but please look at the GNU sed manual for more information. The 's/,$//'
is telling sed
to look for any commas at the end of a line and substitute them with nothing. This is removing all the commas from the end of each line on sed
's standard input.
下一张我们将看看在IS TR\\\\ N,
。同样, TR
可以做很多事情,但它的目的是把字符。请参见 TR手册页获得更详细的解释。这种用法是把所有的UNIX换行符( \\ n
)插入逗号。在 \\
有一个额外的 \\
因为命令行会认为 \\进行转义ñ
作为新行并中断该命令。
The next piece we'll look at at is tr "\\n" ","
. Again, tr
can do many things but its purpose is to transform characters. See tr man page for a more detailed explanation. This usage is to turn all UNIX newline characters (\n
) into commas. The \
has to be escaped with an additional \
because the command line would treat the \n
as a new line and break the command.
接下来是指派,进程名称
。为了完整这里是指派,手册页。 指派,
简单地打印任何正在运行的进程的选择标准匹配到标准输出的进程ID(PID)。每个PID将在本身一行进行打印。在这里,我们正在寻找的命令进程名的pid
。
Next is pgrep process-name
. For completeness here is the pgrep man page. pgrep
simply prints the process id (pid) of any running process that matches the selection criteria to standard out. Each pid will be printed on a line by itself. Here we are looking for the pid of the command process-name
.
现在管道( |
)。这将创建一个新的进程,并在新的过程中发送任何标上印出来的标准。
Now for pipe (|
). This creates a new process and sends anything printed on standard out to the standard in of the new process.
让我们看一下这些命令,了解如何管工作更好。 指派,进程名称| TR\\\\ N,
将打印所有PID的匹配进程名称
到标准输出被传递到进程的标准输入运行 TR
。 TR\\\\ N,| SED的/,$ //'
将改变从它的标准都换行到逗号和打印结果到标准输出被传递到新的进程中运行 sed的' S /,$ //'
。
Lets look at the commands to understand how pipe works better. pgrep process-name | tr "\\n" ","
will print all pid's matching process-name
to standard out which is passed to the standard input of the process running tr
. tr "\\n" "," | sed 's/,$//'
will transform all newlines from its standard in to commas and print the result to its standard out which is passed to the new process running sed 's/,$//'
.
所以整个命令指派,进程名称| TR\\\\ N,| SED的/,$ //'
将打印PID的一个空间分隔行具有名称的任何正在运行的进程进程名称
。
So the entire command pgrep process-name | tr "\\n" "," | sed 's/,$//'
will print a space separated line of pid's for any running process that has the name process-name
.
两个多件查看:顶-p
和反引号(``)。反引号创建运行中的命令,并替换其标准输出被评为整个命令之前,一个新的进程。例如:
Two more pieces to look at: top -p
and the backticks (``). Backticks creates a new process that runs the commands inside and substitutes its standard out before the entire command is evaluated. For example:
echo `echo "Hello, World!"`
打印的Hello,World!
到屏幕上。
最后,顶-p
采用PID和报告各种信息,例如运行时,内存使用量和nice值的列表。如需更详细的解释见href=\"http://linux.die.net/man/1/top\" rel=\"nofollow\">头号人物页面的
Lastly, top -p
takes a list of pids and reports various information such as run time, memory usage and nice value. For a more detailed explanation see the top man page.
这篇关于什么是以下&QUOT的语法的简要说明;顶"命令:顶部-p`指派,进程名称| TR" \\\\ N'QUOT; "," | SED的/,$ //'`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!