强大的管道符及组合命令

xiaoxiao2021-02-28  89

管道符,可以把两条命令连起来,具体来说有两种应用,如下:

1. 例如: ps aux | grep "media"  在 ps aux中的結果中查找media。

2. 例如:   find . -name "*.cpp" | xargs grep "class" -n --color=auto   把find的结果当成参数传入到grep中,即在那些文件内部查找class关键字。

一个复杂的例子:

svn status | xargs -i expr substr {} 9 100 | xargs -i cp {} ~/Desktop/

find . -name "*.xml" | xargs grep  -l "com.lib.ui.common.TempTitle" | xargs -i  sed -i "s/com.lib.ui.common.TempTitle/com.common.widget.TempTitle/g"  {}

svn中显示buildversion的命令:

svn info | grep "Revision" | xargs -i  expr substr {} 11 100

转载请注明原文地址: https://www.6miu.com/read-68402.html

最新回复(0)