首页 > 其他 > 详细

xargs 命令使用

时间:2020-09-08 16:20:57      阅读:56      评论:0      收藏:0      [点我收藏+]

作用:

(1)将前一个命令的标准输出传递给下一个命令,作为它的参数,xargs的默认命令是echo,空格是默认定界符

(2)将多行输入转换为单行

使用模式:

front command | xargs -option later command

front command:前一个命令

-option:xargs的选项

later command:后一个命令

常用参数:

-n:指定一次处理参数的个数

-d:自定义参数界定符

-p:询问是否允许later command 参数

-t:表示先打印命令,然后再执行

-i:逐项处理

其他参考:man xargs

example:

测试文本:test.txt

a b c d e f g 
h i j k l m n 
o p q
r s t
u v w x y z

(1)多行输入单行输出

cat test.txt | xargs

结果:

a b c d e f g h i j k l m n o p q r t s u v w x y z

(2)指定一次处理的参数个数:指定为5,多行输出

cat  test.txt |xargs -n 5

结果:

a b c d e 
f g h i j 
k l m n o
p q r t s
u v w x y 
z

(3)自定义参数界定符:指定界定符为‘m’

cat test.txt | xargs -d m

结果:

a b c d e f g 
h i j k l   n 
o p q
r s t
u v w x y z

(4)询问是否运行later command 参数

cat test.txt | xargs -n 5 -p

结果:

技术分享图片

(5)删除指定名称的进程:进程名为Deadpool

ps -ef | grep ‘Deadpool‘ | grep -v grep|  awk {print $2}‘ | xargs kill -9

 

xargs 命令使用

原文:https://www.cnblogs.com/xiaohaigegede/p/13632838.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!