2016-08-07 26 views
0

我只是想刪除我的本地機器中的所有流浪者箱子。下面是我的箱子:如何正確使用xargs?

$ vagrant box list 
centos/7     (virtualbox, 1509.01) 
coreos-alpha    (virtualbox, 1010.1.0) 

首先字符串(如「的CentOS/7」)在每一行似乎是盒子的名字,所以我嘗試下面的命令:

$ vagrant box list | awk '{ print $1; }' | xargs vagrant box remove 

我只是試圖獲得第一個字符串,並使用xargs將它傳遞給vagrant box remove,因爲我想將該字符串作爲該命令的參數。但是,我以某種方式得到了以下錯誤。我錯過了什麼?

This command was not invoked properly. The help for this command is 
available below. 

Usage: vagrant box remove <name> 

Options: 

    -f, --force      Remove without confirmation. 
     --provider PROVIDER   The specific provider type for  the box to remove 
     --box-version VERSION  The specific version of the box  to remove 
     --all      Remove all available versions  of the box 
    -h, --help      Print this help 

感謝,

回答

3

我覺得xargs的是合併多個框成一個單一的命令,因爲這是默認的行爲。嘗試使用-n開關強制每個命令一個參數:

$ vagrant box list | awk '{ print $1; }' | xargs -n 1 vagrant box remove 
+0

謝謝cyberz! '-n 1'正是我需要的東西。 – aeas44