
文章名《【Python爬虫五十个小案例】爬取中国天气网城市天气》 作者:小馒头学Python
评价:
本文详细介绍了使用Python进行天气数据爬取的全过程,从准备工具到代码实现,再到数据保存,内容详实且实用性强。非常适合初学者学习和实践。
文章链接:https://cloud.tencent.com/developer/article/2472933
gzip是 Linux 系统中一个非常常用的命令,用来压缩文件。它使用 Lempel-Ziv 编码 (LZ77) 和霍夫曼编码的组合来减少文件大小。gzip 命令创建的文件通常以 .gz 作为扩展名。
使用--help选项,查询gzip命令的基本帮助信息。
[root@openEuler-test ~]# gzip --help
Usage: gzip [OPTION]... [FILE]...
Compress or uncompress FILEs (by default, compress FILES in-place).
Mandatory arguments to long options are mandatory for short options too.
-c, --stdout write on standard output, keep original files unchanged
-d, --decompress decompress
-f, --force force overwrite of output file and compress links
-h, --help give this help
-k, --keep keep (don't delete) input files
-l, --list list compressed file contents
-L, --license display software license
-n, --no-name do not save or restore the original name and timestamp
-N, --name save or restore the original name and timestamp
-q, --quiet suppress all warnings
-r, --recursive operate recursively on directories
--rsyncable make rsync-friendly archive
-S, --suffix=SUF use suffix SUF on compressed files
--synchronous synchronous output (safer if system crashes, but slower)
-t, --test test compressed file integrity
-v, --verbose verbose mode
-V, --version display version number
-1, --fast compress faster
-9, --best compress better
With no FILE, or when FILE is -, read standard input.
Report bugs to <bug-gzip@gnu.org>.gzip(选项)(参数)参数 | 描述 |
|---|---|
-c, --stdout | 将结果输出到标准输出,保持原始文件不变。 |
-d, --decompress | 解压缩。 |
-f, --force | 强制覆盖输出文件并压缩链接。 |
-h, --help | 显示此帮助信息。 |
-k, --keep | 保留(不删除)输入文件。 |
-l, --list | 列出压缩文件的内容。 |
-L, --license | 显示软件许可证。 |
-n, --no-name | 不保存或恢复原始文件名和时间戳。 |
-N, --name | 保存或恢复原始文件名和时间戳。 |
-q, --quiet | 抑制所有警告。 |
-r, --recursive | 对目录递归操作。 |
--rsyncable | 创建适合 rsync 的存档。 |
-S, --suffix=SUF | 在压缩文件上使用后缀 SUF。 |
--synchronous | 同步输出(如果系统崩溃更安全,但速度较慢)。 |
-t, --test | 测试压缩文件的完整性。 |
-v, --verbose | 详细模式。 |
-V, --version | 显示版本号。 |
-1, --fast | 更快地压缩。 |
-9, --best | 更好地压缩。 |
[root@openEuler-test ~]# mkdir /test && cd /test
[root@openEuler-test test]# ls
[root@openEuler-test test]# touch file{01..10}
[root@openEuler-test test]# ls
file01 file02 file03 file04 file05 file06 file07 file08 file09 file10
[root@openEuler-test test]# echo aatest > /test/file01[root@openEuler-test test]# gzip file01
[root@openEuler-test test]# ll
total 4
-rw-r--r-- 1 root root 34 Sep 29 09:17 file01.gz
-rw-r--r-- 1 root root 0 Sep 29 09:16 file02
-rw-r--r-- 1 root root 0 Sep 29 09:16 file03
-rw-r--r-- 1 root root 0 Sep 29 09:16 file04
-rw-r--r-- 1 root root 0 Sep 29 09:16 file05
-rw-r--r-- 1 root root 0 Sep 29 09:16 file06
-rw-r--r-- 1 root root 0 Sep 29 09:16 file07
-rw-r--r-- 1 root root 0 Sep 29 09:16 file08
-rw-r--r-- 1 root root 0 Sep 29 09:16 file09
-rw-r--r-- 1 root root 0 Sep 29 09:16 file10如果我们想保留原始文件,使用
-k选项。
[root@openEuler-test test]# gzip -k file02
[root@openEuler-test test]# ll
total 8
-rw-r--r-- 1 root root 34 Sep 29 09:17 file01.gz
-rw-r--r-- 1 root root 0 Sep 29 09:16 file02
-rw-r--r-- 1 root root 27 Sep 29 09:16 file02.gz
-rw-r--r-- 1 root root 0 Sep 29 09:16 file03
-rw-r--r-- 1 root root 0 Sep 29 09:16 file04
-rw-r--r-- 1 root root 0 Sep 29 09:16 file05
-rw-r--r-- 1 root root 0 Sep 29 09:16 file06
-rw-r--r-- 1 root root 0 Sep 29 09:16 file07
-rw-r--r-- 1 root root 0 Sep 29 09:16 file08
-rw-r--r-- 1 root root 0 Sep 29 09:16 file09
-rw-r--r-- 1 root root 0 Sep 29 09:16 file10使用-d选项,进行解压文件。
[root@openEuler-test test]# gzip -d file01.gz
[root@openEuler-test test]# ll
total 8
-rw-r--r-- 1 root root 7 Sep 29 09:17 file01
-rw-r--r-- 1 root root 0 Sep 29 09:16 file02
-rw-r--r-- 1 root root 27 Sep 29 09:16 file02.gz
-rw-r--r-- 1 root root 0 Sep 29 09:16 file03
-rw-r--r-- 1 root root 0 Sep 29 09:16 file04
-rw-r--r-- 1 root root 0 Sep 29 09:16 file05
-rw-r--r-- 1 root root 0 Sep 29 09:16 file06
-rw-r--r-- 1 root root 0 Sep 29 09:16 file07
-rw-r--r-- 1 root root 0 Sep 29 09:16 file08
-rw-r--r-- 1 root root 0 Sep 29 09:16 file09
-rw-r--r-- 1 root root 0 Sep 29 09:16 file10查看压缩比率::使用 -l 选项可以列出每个被压缩文件的信息,包括未压缩的大小、压缩后的大小、压缩比等信息
[root@openEuler-test test]# gzip -l file01.gz
compressed uncompressed ratio uncompressed_name
34 7 -28.6% file01gzip -c file03 > file01.gzgzip -dc file01.gz > file03可以一次性压缩多个文件
gzip file02 file03 file04[root@openEuler-test test]# mkdir -p test01/test03
[root@openEuler-test test]# echo aa > test01/test03/aa.txt
[root@openEuler-test test]# echo bb > test01/bb.txt递归进行压缩目录:所有test01目录下面的文件都变成了.gz,目录依然存在只是目录里面的文件相应变成了.gz.这就是压缩,和打包不同。因为是对目录操作,所以需要加上-r选项,这样也可以对子目录进行递归了。
[root@openEuler-test test]# gzip -rv test01/
test01/test03/aa.txt: -66.7% -- replaced with test01/test03/aa.txt.gz
test01/bb.txt: -66.7% -- replaced with test01/bb.txt.gz
[root@openEuler-test test]# ll
total 4
drwxr-xr-x 3 root root 4096 Sep 29 09:42 test01
[root@openEuler-test test]# tree ./
./
└── test01
├── bb.txt.gz
└── test03
└── aa.txt.gz
3 directories, 2 files[root@openEuler-test test]# gzip -dr test01
[root@openEuler-test test]# tree ./
./
└── test01
├── bb.txt
└── test03
└── aa.txt
3 directories, 2 files使用 -t 选项可以检查 .gz 文件是否完整且没有损坏
gzip -t file01.txt.gzgzip 会替换原始文件,除非你加上 -k 选项来保留原文件。gzip 不支持直接压缩整个目录,需要先将目录打包成一个文件(如通过 tar)再进行压缩。.gz 文件的完整性,可以使用 gzip -t 选项避免在解压损坏文件时丢失数据。原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。