xargs -I replace-str option difference
- by foresightyj
From my understanding, the following should mean exactly the same:
ls -1 | xargs file {}
ls -1 | xargs -I{} file {}
if -I option is not specified, it is default to -I{}.
I want to list all files in the current directory and run file command on each of them. Some have spaces in their names. However, I noticed the difference. See below:
$ ls -1
Hello World
$ ls -1 | xargs file {}
{}: ERROR: cannot open `{}' (No such file or directory)
Hello: ERROR: cannot open `Hello' (No such file or directory)
World: ERROR: cannot open `World' (No such file or directory)
$ ls -1 | xargs -I{} file {}
Hello World: directory
With -I{} explicitly specified, blanks in file names are treated as expected.