-rw-r--r-- 1 root root 117386 Nov 25 2009 /etc/Muttrc
linux-yptrs:/ # cp /etc/Muttrc file1
linux-yptrs:/ # ll file1
-rw-r--r-- 1 root root 117386 Jul 20 13:24 file1
linux-yptrs:/ # gzip file1 //压缩file1文件
linux-yptrs:/ # ll file1.gz
-rw-r--r-- 1 root root 33421 Jul 20 13:24 file1.gz
linux-yptrs:/ # gzip -l file1.gz
compressed uncompressed ratio uncompressed_name
33421 117386 71.5% file1
linux-yptrs:/ # gzip -d file1.gz //解压缩FILE1文件
linux-yptrs:/ # ll file1
-rw-r--r-- 1 root root 117386 Jul 20 13:24 file1
linux-yptrs:/ # gunzip file1.gz //gunzip和gzip -d一致
linux-yptrs:/ # ll file1
-rw-r--r-- 1 root root 117386 Jul 20 13:24 file1
压缩gzip后,原来的文件会消失成为file.gz的压缩文件;
但是可以通过gzip中的参数-c,保留原来的文件不消失;
linux-yptrs:/ # gzip -c file1 > file1.gz
linux-yptrs:/ # ll file*
-rw-r--r-- 1 root root 117386 Jul 20 13:24 file1
-rw-r--r-- 1 root root 33421 Jul 20 13:31 file1.gz
另外-c还可以将多个文件的内容合并为一个压缩文件保存
linux-yptrs:/ # touch file2
linux-yptrs:/ # vi file2
apple
bag
cat
dog
egg
fog
ghost
linux-yptrs:/ # gzip -c file1 file2 > file3.gz
linux-yptrs:/ # gzip -d file3.gz //gunzip file3.gz
linux-yptrs:/ # tail -10 file3
# to the one used by ``$status_format''.
#
#
apple
bag
cat
dog
egg
fog
ghost
linux-yptrs:/ # gzip -d file3.gz //解压FILE3.GZ
linux-yptrs:/ # ls
file1.gz file3 file1 file2.gz file2
//发现原来的file3.gz压缩文件解压以后也没有了,如何看压缩文件而不用
解压呢?
1)先解压,在通过gzip -c file > file.gz
2)通过 gzip -d -c file.gz 即可
linux-yptrs:/ # gzip -d -c file3.gz | grep bag
bag
内容的附加压缩到同一个文件
linux-yptrs:/ # gzip -c file2 >file4.gz
linux-yptrs:/ # gzip -d -c file4.gz
apple
bag
linux-yptrs:/ # gzip -c file3 > file4.gz
linux-yptrs:/ # gzip -d -c file4.gz
cat
dot
//发现此时file4.gz的内容会被file3所覆盖;所以我们可用>>符号来传输
linux-yptrs:/ # gzip -c file2 > file4.gz
linux-yptrs:/ # gzip -c file3 >> file4.gz
linux-yptrs:/ # gzip -d -c file4.gz
apple
bag
cat
dot
linux-yptrs:/ # zcat file4.gz
apple
bag
cat
dot
如何将文件下的文件压缩,以及文件夹下的子文件夹文件压缩
linux-yptrs:/ # mkdir -p dir/dir1
linux-yptrs:/ # cp file2 dir/file2_1
linux-yptrs:/ # cp file3 dir/dir1/file3_1
linux-yptrs:/ # gzip -r dir //-r参数进行递归压缩
linux-yptrs:/ # cd dir/
linux-yptrs:/dir # ls
dir1 file2_1.gz
linux-yptrs:/dir # cd dir1/
linux-yptrs:/dir/dir1 # ls
file3_1.gz
递归解压缩
linux-yptrs:/ # gunzip -r dir
linux-yptrs:/ # cd dir/
linux-yptrs:/dir # ls
dir1 file2
linux-yptrs:/dir # cd dir1/
linux-yptrs:/dir/
dir1 # ls
file3下载本文