---
title: "xargs"
author: "elihe2011"
date: "2013-07-08T15:51:42Z"
tags: []
categories: ["操作系统"]
slug: "xargs"
draft: false
lastmod: "2013-07-08T15:51:42Z"
id: 1901427
url: "https://elihe2011.iteye.com/blog/1901427"
---

```
xargs：产生某个命令行参数，xargs可以读入stdin的数据，并且以空格或换行符做分割，将stdin分割成arguments

xargs [-0pen] command
-0: stdin含特殊字符(`,\,空格等)，可将这些字符还原成普通字符，让其失去特殊意义
-p: prompt，没执行一个argument，都询问
-e: EOF(end of file)，后面接一个字符，当xargs分析道这个字符串时，停止继续工作
-n: 后接次数，每次command执行时，要使用几个参数

eg:
cut -d":" -f1 /etc/passwd | head -n 3 | xargs -p finger

cut -d":" -f1 /etc/passwd | xargs -p -e"lp" finger

ls 不支持管道流：
find /sbin -perm +7000 | ls -l   # 得到当前目录下文件列表
find /sbin -perm +7000 | xargs ls -l   # 正确
```