Doubt in xargs command

Hi,

What is the difference in capitalizing the option 'i' of xargs command, (i.e) xargs -i and xargs -I?

Also, what is the difference between the below 2 commands?

output_from_cmd | xargs  -I {} grep '{}' file
output_from_cmd | xargs  -I grep '{}' file

Any efficiency or performance improvement?

What does your man page say about it?

No.

From man xargs:

grep reads from a pipe/stdin so there should be no need for xargs in your case.

Thank you zaxxon :slight_smile:

So what I inferred from you is: -I replace-str is equal to -i [replace-str] (optional)

And, -I {} is deprecated, instead of that just '-I' is enough. Have I got your right?

And, more from 'man' page:

When you use the -I option, each line read from the input is buffered internally.
This means that there is an upper limit on the length of input line that xargs will accept when used with the -I option.

It means the following:
Using -i is old, depricated, ie. should be no longer used. Instead, you should use -I . The curled brackets {} is just the string, which should be replaced by the argument which is being handed over to xargs. So you can position it in the line's syntax. You could use other characters but the curled brackets instead. This placeholder is just being defined with -I , example:

$> echo bla| xargs -I_ touch _
$> ls bla
bla

In this case I just took a single underscore instead of opening and closing curled bracket. Curled brackets are just some kind of "standard" for this most people use because it is or might be easier to read. If there would be more than one usage of the argument in a command's syntax (for example let's say 2), you could use 2 times the _ or {} or whatever character(s) you defined with -I as placeholder in your following command supplied by xargs. Example:

$> touch file1 file2 file3
$> ls -1
file1
file2
file3
$> ls -1| xargs -I_ mv _ _.txt
$> ls -1
file1.txt
file2.txt
file3.txt

In simple cases where you have just 1 argument being passed to xargs and it should be placed at the end your command, you don't even have to use -I as xargs just places it automatically at the end of the command:

echo 5| xargs touch
1 Like