视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
linux gzip压缩
2025-09-29 10:53:48 责编:小OO
文档
linux-yptrs:/ # ll /etc/Muttrc

-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下载本文

显示全文
专题