Skip to content

Instantly share code, notes, and snippets.

@ibreathebsb
Last active August 28, 2018 06:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ibreathebsb/09dd6713d4833af3b4d44366864ab575 to your computer and use it in GitHub Desktop.
Save ibreathebsb/09dd6713d4833af3b4d44366864ab575 to your computer and use it in GitHub Desktop.

gzip

gzip 用于压缩解压查看文件

用法: gzip [opitions] file

-v: 显示压缩和解压缩信息

-k: 压缩和解压时保留原来的文件

-c: 将压缩或解压的结果输出的stdout‘

-d: 解压缩

-[1~9]: 数字越大压缩程度越高,但是压缩速度会变慢,默认6

➜  Playground dd if=/dev/zero of=./test bs=1024 count=1024
➜  Playground gzip -vk9 ./test
./test:		   99.8% -- replaced with ./test.gz
➜  Playground ls -l ./test*
-rw-r--r--  1 isaac  staff  1048576  8 28 09:04 ./test
-rw-r--r--  1 isaac  staff     1056  8 28 09:04 ./test.gz
➜  Playground gzip -dc ./test.gz >> output //解压并重命名
➜  Playground ls -al
total 4120
drwxr-xr-x   6 isaac  staff      192  8 28 09:08 .
drwxr-xr-x+ 58 isaac  staff     1856  8 28 09:08 ..
-rw-r--r--@  1 isaac  staff     6148  8 27 09:43 .DS_Store
-rw-r--r--   1 isaac  staff  1048576  8 28 09:08 output
-rw-r--r--   1 isaac  staff  1048576  8 28 09:04 test
-rw-r--r--   1 isaac  staff     1056  8 28 09:04 test.gz
➜  Playground gzip -c ./test.gz //将压缩文件的内容输入到stdout
���[test.gz����h����\�Z\���!#á_�s9�0��Q0
F�c�ye���A��B5� %

如果想要对压缩或者解压的生成文件进行重命名,可以输出到stdout然后重定向,例如gzip -c ./test >> name.gz

查看压缩文件内容 gzip -cd file.gz | gzcat file.gz

@ibreathebsb
Copy link
Author

bzip2

用法基本与gzip一致,压缩效率更高些,压缩文件名默认为filename.bz2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment