gzip
壓縮與傳輸
用法
gzip [-k] <file>把單個檔案壓成 .gz,而且預設在成功後刪掉原檔,想留著就加 `-k` 或用 `-c` 寫到標準輸出;它從不打包多個檔案,所以前面要配 tar。
常用選項
| 選項 | 含義 |
|---|---|
| -k | Keep the original. Without it, gzip deletes the file it just compressed. |
| -d | Decompress, which is exactly what gunzip does. |
| -c | Write to stdout and leave the input alone. |
| -1 / -9 | Fastest / smallest. The default is -6. |
| -l | Show the compressed and original sizes of a .gz file. |
| -t | Test the integrity without unpacking. |
| -r | Walk a directory and compress each file separately. |
範例
gzip -9 access.logCreates access.log.gz. The original access.log is gone.
gzip -c report.csv > report.csv.gzCompress while keeping the original.
gzip -l backup.sql.gzHow much it actually saved.
打包和壓縮是兩件事:tar 打包,gzip 壓小,.tar.gz 是兩樣一起。
怎麼看
- 方括號 [ ] 表示這部分可以不寫。
- 省略號 … 表示可以寫多個。
- 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。
常見問題
Q. gzip 是做什麼的?
把單個檔案壓成 .gz,而且預設在成功後刪掉原檔,想留著就加 `-k` 或用 `-c` 寫到標準輸出;它從不打包多個檔案,所以前面要配 tar。
Q. 怎麼寫?
gzip [-k] <file> —— 方括號表示可以省略的部分。
Q. 值得記的選項有幾個?
這裡列了 7 個,完整列表在 man gzip。這條命令屬於壓縮與傳輸。
相關命令
man 手冊: man gzip