When i pipe to gzip it can not accept stdin i should using xargsto convert stdin to argument
$ls
1.txt
$ls |xargs gzip && ls
1.txt.gz
every thing is ok . but when i want to compress a cpio archive file
$ls | cpio -ov | gzip > archive.cpio.gz
also it is ok and this ls | cpio -ov | xargs gzip does not work.why in the second situation gzip accept stdin and it can not accept argument?
xargsreads text from its standard input (usually you use a pipe to get another command's output there) and constructs a new command line composed of its own arguments and the text from standard input and executes that new command. It does not care whether the input are file names or anything else, just in your example it makes only sense with file names. – Byte Commander Sep 29 '16 at 13:26cmd1 | cmd2cmd 2 see a text from its stdin and it can not recognizable for those command that accept file names as argument....in my example entire data (not only file name) write to stdout and it is possible for pipe to gzip without xargs, are these correct? – Sinoosh Sep 29 '16 at 13:49