Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Dec 312009

How to adjust the argument position in xargs?


Sometimes you might want to adjust the argument position when using the xargs command, e.g.

echo "foo" | xargs echo "bar"

It gives:

bar foo

Instead, you want the piped argument "foo" to be inserted before the "bar", you can use

echo "foo" | xargs -i echo {} "bar"

Now it gives:

foo bar

That's very handy

  3 Responses to “How to adjust the argument position in xargs?”

  1. With GNU Parallel you do not need the -i:

    echo "foo" | parallel echo {} "bar"

    and you get the added advantage the jobs will be run in parallel.

    Watch the intro video to GNU Parallel:

  2. Hello,

    Thanks for you tips.

    Unfortunately, parallel is not included in most common distributions like Ubuntu.

  3. It seems from "man xargs", the -i option is deprecated. They suggest to use "-I". I tried the following example and it works:

    echo "foo" | xargs -I % echo % "bar" ~
    foo bar

 Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>