When i pipe to gzip
it can not accept stdin i should using xargs
to 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?
There is a difference between command-line arguments and standard input.
gzip
accepts filenames as arguments. It will read the raw data from the specified files and compress them. If you have a command outputting a list of filenames, you can usexargs
to pass those filenames togzip
as command-line arguments.However, if no file arguments are passed to
gzip
, it defaults to read its raw data from standard input and print the compressed result to standard output. If you have a command outputting raw data which you want to compress, you can pipe it togzip
.