2021-11-14 15:52:46 +08:00

42 lines
1.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: "xargs 命令"
date: 2019-10-29T18:43:36+08:00
lastmod: 2019-10-29T18:46:00+08:00
keywords: []
tags: ["shell", "xargs"]
categories: ["shell"]
---
## 基本使用
- 把标准输入转换成命令行参数,传递给 xargs 后的命令使用
```bash
echo 'one two three' | xargs mkdir
# 等于
mkdir one two three
```
- 默认命令 echo
```bash
seq 1 8 | xargs
# 等于
seq 1 8 | xargs echo
```
- -d 指定分隔符,默认是换行和空格
```bash
echo -e "a\tb\tc" | xargs -d "\t" echo
```
- -p 打印出要执行的命令,并询问用户是否执行
- -t 打印出要执行的命令,直接执行
- -0 指定 null 当作分隔符,一般用于分隔包含空格的字符串列表
```bash
find /path -type f -print0 | xargs -0 rm
```
- -L 指定标准输入中的多少行作为一个参数
- -n 一行中可能包含空格分隔的多项,该参数指定每次将多少项作为命令行参数
- -I 指定每一项命令行参数的替代字符串
```bash
seq 1 8 | xargs -I PAT echo PAT
```
- -P 指定同时使用多少个进程执行命令默认只用一个0 表示不限制
- --show-limits 查看系统命令行缓冲上限