Gzip -c 通過管道重要嗎?

Gzip -c 通過管道重要嗎?

我有時看到兩種寫作方式:有和沒有-c

以下 2 個案例輸出相同且速度相同嗎?

mysqldump -u root dbname | gzip > test.sql
mysqldump -u root dbname | gzip -c > test.sql

那麼連續管道呢?

mysqldump -u root dbname | gzip | anotherprogram

感謝您澄清

答案1

根據man gzip
如果未指定文件,或文件名為“-”,則標準輸入將被壓縮到標準輸出。

在所有情況下,您都將來源流傳輸到gzipSTDIN,而不指定要壓縮為來源檔案的內容。在這些情況下,gzip預設將壓縮流傳送到 STDOUT,這使得-c選項無用/冗餘。

-c您在這種情況下gzip這樣調用gzip -c sourceFile而不是
壓縮sourceFile+新增副檔名GZ+刪除sourceFile
它將發送壓縮流到 STDOUT 並且不會刪除原始檔
例如:

gzip -c sourceFile | anotherProgram

相關內容