2016-03-18 34 views
1

我是新來xargs的..如何使用的mkdir與xargs的

我想使用xargs的MKDIR創建一個類似於某些文件夾:

for i in {1..11};do mkdir mm$i;done 

這將創建文件夾MM1,平方毫米,平方毫米... MM11

我想:

echo {1..11}|xargs -p -n1 -I {} mkdir -p "mm{}" 

但它提示:

mkdir -p mm1 2 3 4 5 6 7 8 9 10 11 ?... 

我也嘗試:

echo {1..11}|xargs -p -n1 mkdir -p mm 

它提示:

mkdir -p mm 1 ?...n 
mkdir -p mm 2 ?...n 
mkdir -p mm 3 ?...n 
mkdir -p mm 4 ?...n 
mkdir -p mm 5 ?...n 
mkdir -p mm 6 ?...n 
mkdir -p mm 7 ?...n 
mkdir -p mm 8 ?...n 
mkdir -p mm 9 ?...n 
mkdir -p mm 10 ?...n 
mkdir -p mm 11 ?...n 
mkdir -p mm ?...n 

幫助.. TKS

+4

請勿使用'xargs',請使用'mkdir mm {1..11}'。 –

+0

tks !! ñ我只是用於........ BW不知道什麼將與xargs一起工作,因爲這種方式工作,但mkdir不工作.. – once

回答

1

你的問題是,你正在使用的-I標誌,它要求 參數用空行而不是空白分隔:

-I replace-str 
     Replace occurrences of replace-str in the initial-arguments with 
     names read from standard input. Also, unquoted blanks do not 
     terminate input items; instead the separator is the newline 
     character. Implies -x and -L 1. 

一種解決方案是產生適當的輸入:

echo {1..11} | tr ' ' '\n' | xargs ... 

或者:

seq 11 | xargs ... 

或者,如@gniourf_gniourf表明在評論,只是使用殼 膨脹直接對於該特定案件。

+0

我以爲-n標誌有助於添加下一行 – once