我得到了一个~400MB 的 zip 文件,其中有一些大小大约在 400MB - 1GB 范围内的 txt/json 文件。
我只是想查看目标文件的前 100 行,而不必从 zip 中提取它,也不会占用太多内存。(非常低)
或者是否有一个选项可以拆分 zip 中的目标文件,而无需提取并按顺序执行,即,当给出split
50MB 的命令时,例如,我只获得第一个拆分文件,查看它,然后继续拆分第二个文件,查看它,继续拆分第三个 50MB 的文件,查看它,一次又一次?
答案1
好的,步骤如下:
要获取存档中您想要查看其内容的文件的名称,请使用以下命令列出(zip 文件)的内容:
unzip -l file.zip
现在查看第一
100
行:unzip -c file.zip file/name_of_file_of_interest.json | head -100
笔记:
这种格式
unzip -c file.zip file/name_of_file_of_interest.json
是需要的,不是
unzip -c file.zip name_of_file_of_interest.json
获取文件的路径,运行命令时将获取该路径
step 1
。
例子:
文件
unzip -l wordpress-4.7.zip
,产生... 0 2016-12-06 19:40 wordpress/wp-includes/Text/Diff/Renderer/ 5535 2010-02-19 02:25 wordpress/wp-includes/Text/Diff/Renderer/inline.php 6813 2015-06-28 16:27 wordpress/wp-includes/Text/Diff/Renderer.php 12950 2015-06-28 16:27 wordpress/wp-includes/Text/Diff.php 14460 2016-12-02 08:11 wordpress/wp-includes/class-wp-hook.php 34760 2016-12-01 03:19 wordpress/wp-includes/rest-api.php 23621 2016-11-21 03:46 wordpress/wp-includes/update.php 102116 2016-12-04 21:37 wordpress/wp-includes/comment.php 14066 2016-08-25 18:37 wordpress/wp-includes/class-wp-text-diff-renderer-table.php 2853 2015-12-16 10:58 wordpress/wp-config-sample.php
现在我想查看
100
文件的第一行wp-config-sample.php
,wordpress-4.7.zip
因此我执行以下操作:unzip -p wordpress-4.7.zip wordpress/wp-config-sample.php | head -100
更多信息:
为什么使用
-p
选项:-p extract files to pipe (stdout). Nothing but the file data is sent to stdout, and the files are always extracted in binary format, just as they are stored (no conversions).
更优雅的输出是less
less wordpress-4.7.zip
# OUTPUT
Archive: wordpress-4.7.zip
Length Method Size Cmpr Date Time CRC-32 Name
-------- ------ ------- ---- ---------- ----- -------- ----
0 Stored 0 0% 2016-12-06 19:40 00000000 wordpress/
16250 Defl:X 4157 74% 2016-11-29 06:39 2b3bf692 wordpress/wp-settings.php
3286 Defl:X 1397 58% 2015-05-24 18:26 e732ef29 wordpress/wp-cron.php
1627 Defl:X 799 51% 2016-08-29 13:00 d0339e89 wordpress/wp-comments-post.php
5447 Defl:X 2006 63% 2016-09-27 22:36 888ccd8b wordpress/wp-activate.php
0 Stored 0 0% 2016-12-06 19:40 00000000 wordpress/wp-admin/
2401 Defl:X 933 61% 2016-10-24 05:45 1e03d7a9 wordpress/wp-admin/link-parse-opml.php
0 Stored 0 0% 2016-12-06 19:40 00000000 wordpress/wp-admin/js/
12000 Defl:X 3291 73% 2016-09-13 07:03 77f8b8cb wordpress/wp-admin/js/editor.js
6224 Defl:X 2215 64% 2016-11-03 06:40 693a34f0 wordpress/wp-admin/js/user-profile.min.js
1508 Defl:X 640 58% 2015-07-27 12:19 ee45bde7 wordpress/wp-admin/js/word-count.min.js
5148 Defl:X 2010 61% 2016-11-17 19:28 2384dae7 wordpress/wp-admin/js/tags-suggest.js
6842 Defl:X 2399 65% 2016-10-23 19:16 41742fcd wordpress/wp-admin/js/tags-box.js
17717 Defl:X 5102 71% 2016-07-05 14:37 93dfd6b0 wordpress/wp-admin/js/image-edit.js
34299 Defl:X 7077 79% 2016-11-04 18:18 97b89baa wordpress/wp-admin/js/updates.min.js
4192 Defl:X 1539 63% 2016-06-08 23:37 b8c4c822 wordpress/wp-admin/js/postbox.min.js
20983 Defl:X 6187 71% 2016-11-03 06:40 3aec32c2 wordpress/wp-admin/js/nav-menu.min.js
25330 Defl:X 7009 72% 2016-11-03 06:40 43591b6e wordpress/wp-admin/js/theme.min.js
1502 Defl:X 707 53% 2013-11-14 06:40 4dc0acc0 wordpress/wp-admin/js/custom-header.js
11462 Defl:X 4344 62% 2016-11-03 06:40 0aa95325 wordpress/wp-admin/js/press-this.min.js