What does xargs do if it’s used without any parameter

xargs

[user@notebook ~] echo -e '1\n2\n3\n4'
1
2
3
4
[user@notebook ~] echo -e '1\n2\n3\n4' | xargs
1 2 3 4
[user@notebook ~] 

My question: So xargs removes the newlines if it's used without parameters?

Best Answer

quoting the manpage:

xargs reads items from the standard input, delimited by blanks (which can be protected with double or single quotes or a backslash) or newlines, and executes the command (default is /bin/echo) one or more times with any initial-arguments followed by items read from standard input. Blank lines on the standard input are ignored.

Because Unix filenames can contain blanks and newlines, this default behaviour is often problematic; filenames containing blanks and/or newlines are incorrectly processed by xargs. In these situations it is better to use the -0 option, which prevents such problems. When using this option you will need to ensure that the program which produces the input for xargs also uses a null character as a separator. If that program is GNU find for example, the -print0 option does this for you.

Related Question