Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to know what is the difference between this

ls | xargs rm

ls | xargs -i{} rm {}

Both are working for me

share|improve this question

migrated from Dec 31 '12 at 15:13

This question came from our site for professional and enthusiast programmers.

up vote 4 down vote accepted

xargs rm will invoke rm with all arguments as parameter departed with spaces.

xargs -i{} rm {} will invoke rm {} for each of the argument and {} will be replaced by the current argument.

If you have 2 arguments a.txt and b.txt, xargs rm will call this

rm a.txt b.txt

But xargs -i{} rm {} will call

rm a.txt
rm b.txt

This is because -i option implies -L 1 option which mean the command rm will get only 1 argument each time.

Check this Ideone link to get more idea about it.

share|improve this answer
WHICH ONE IS BETTER – user19140477031 Dec 31 '12 at 8:32
@user19140477031 depends one what operation you are performing. for rm it does not matter – Shiplu Dec 31 '12 at 8:45

With braces it will spawn one rm process per file. Without the braces, xargs will pass as many filenames as possible to each rm command.


ls | xargs echo


ls | xargs -i echo '{}'
share|improve this answer

-i option (equivalent to --replace) creates a sort of placeholder where xargs stores the input it just received. In your second command, the placeholder is "{}", it works like find -exec option. Once defined, xargs will replace this placeholder with the entire line of input. If you don´t like the "{}" name, you can define your own:


In your case, both commands are producing the same result. In the second form, you are just making explicit the default behaviour with the -i option.

share|improve this answer

You must log in to answer this question.