300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 7zip@命令行压缩@解压缩7z/zip/等各种压缩格式包@查看压缩包内容

7zip@命令行压缩@解压缩7z/zip/等各种压缩格式包@查看压缩包内容

时间:2021-09-11 23:26:45

相关推荐

7zip@命令行压缩@解压缩7z/zip/等各种压缩格式包@查看压缩包内容

文章目录

windows_powershell+scoop+7zip_命令行解压缩7z包references7zip安装@操作windowsscoop方式安装搜索7zip检查是否安装成功查看7zip用法简写获取帮助🎈解压🎈指定解压目录&密码解压到带有空格等特殊字符的目录下压缩🎈refexample权限问题批量压缩🎈指定压缩类型为zip,批量压缩通配符匹配的文件到同一个包中查看压缩包🎈查看压缩文件信息(压缩包内条目)文件/目录名称指定解压示例linux: 7z/p7zipkali:Kali GNU/Linux Rollingubuntu 18zip系列7zCompress-archiveExpand-Archiveexamples

windows_powershell+scoop+7zip_命令行解压缩7z包

references

7zip - unzip file using 7z in powershell - Stack Overflow在线帮助文档(详细+示例):Command Line Syntax - 7-Zip Documentation

7zip安装@操作

windows

scoop方式安装

搜索7zip

🚀 scoop search 7zip'main' bucket:7zip (21.07)7zip19.00-helper (19.00)

检查是否安装成功

检查scoop已安装软件列表

#检查scoop 安装列表7zip🚀 scoop listInstalled apps:NameVersionSource Updated Info----------------- ------- ----7zip21.07 main -05-05 14:05:15coreutils 5.97.3 main -05-05 15:05:07dark3.11.2 main -05-05 14:05:55innounp 0.50 main -05-05 14:05:37lsd 0.21.0 main -04-29 11:04:13neofetch 7.1.0 main -04-29 13:04:41neovim 0.6.1 main -02-23 09:02:09ntop0.3.4 main -04-20 10:04:36psutils 0..02.27 main -02-20 15:02:51

查看7zip用法

 cxxu   ~/Downloads  ﲍ  100    19:12:14 🚀 scoop info 7zipName : 7zipDescription : A multi-format file archiver with high compression ratiosVersion: 21.07Bucket: mainWebsite: https://www.7-License: LGPL-2.1-or-laterUpdated at : /4/4 17:24:43Updated by : Issac LinInstalled : 21.07Binaries : 7z.exeShortcuts : 7-ZipNotes : Add 7-Zip as a context menu option by running: "<root>\install-context.reg"

简写

# 得知,二进制文件可执行文件名为`7z.exe`,可以简写为`7z` cxxu   ~/Downloads  ﲍ  100    19:12:46 🚀 7z.exe7-Zip 21.07 (x64) : Copyright (c) 1999- Igor Pavlov : -12-26Usage: 7z <command> [<switches>...] <archive_name> [<file_names>...] [@listfile]<Commands>a : Add files to archiveb : Benchmarkd : Delete files from archivee : Extract files from archive (without using directory names)h : Calculate hash values for filesi : Show information about supported formatsl : List contents of archivern : Rename files in archivet : Test integrity of archiveu : Update files to archivex : eXtract files with full paths

获取帮助🎈

7-Zip Start Page - 7-Zip DocumentationCommand Line Commands - 7-Zip Documentation7z --help

解压🎈

指定解压目录&密码

-o{Directory} : set Output directory-p{Password} : set Password

这里的花括号表示-o选项和指定的目录名之间没有空格

对于特殊字符,可能需要转义,保护其不被shell解释

例如

7z x .\archive.zip -ooutput7z x .\archive.zip -otarget2PS D:\repos\scripts\jsScripts> lsd --tree .├──  archive.zip├──  clock.js├──  output│ ├──  clock.js│ ├──  theSnippetYourSelectToRun.js│ └──  timeFresher.js├──  target2│ ├──  clock.js│ ├──  theSnippetYourSelectToRun.js│ └──  timeFresher.js├──  theSnippetYourSelectToRun.js└──  timeFresher.js

解压到带有空格等特殊字符的目录下

操作环境:powershell目标目录名为t est(带空格指定测试): 被解压文件:当前目录下的一个名为:winmm.dll.creack_typora.7z的压缩文件7z x .\winmm.dll.creack_typora.7z -o't est'

PS D:\Program Files\Typora> 7z x .\winmm.dll.creack_typora.7z -o't est'7-Zip 21.07 (x64) : Copyright (c) 1999- Igor Pavlov : -12-26Scanning the drive for archives:1 file, 3625220 bytes (3541 KiB)Extracting archive: .\winmm.dll.creack_typora.7z--Path = .\winmm.dll.creack_typora.7zType = 7zPhysical Size = 3625220Headers Size = 138Method = LZMA2:22 BCJSolid = -Blocks = 1Everything is OkSize: 4083712Compressed: 3625220PS D:\Program Files\Typora> ls t*Directory: D:\Program Files\TyporaModeLastWriteTime Length Name----------------- ------ ----d---- 6/26/ 7:53 PM t est-a--- 6/21/ 10:04 PM147465264 ﬓ Typora.exe-a--- 1/19/ 11:19 PM 319  Typora.VisualElementsManifest.xml

压缩🎈

ref

a (Add) command - 7-Zip Documentation

example

-t (Type of archive)

-t选项指定压缩类型(zip表示将文件(夹))压缩为zip文件

压缩成zip文件

PS D:\exes\windowsTools> 7z a -tzip .\PCMaster_Green.zip .\PCMaster\7-Zip 22.01 (x64) : Copyright (c) 1999- Igor Pavlov : -07-15Scanning the drive:23 folders, 88 files, 77793056 bytes (75 MiB)Creating archive: .\PCMaster_Green.zipAdd new data to archive: 23 folders, 88 files, 77793056 bytes (75 MiB)Files read from disk: 88Archive size: 41941641 bytes (40 MiB)Everything is Ok

结果:

PS D:\exes\windowsTools> ls *zipDirectory: D:\exes\windowsToolsModeLastWriteTime Length Name----------------- ------ -----a--- 12/27/ 5:27 PM 41941641  PCMaster_Green.zip

压缩成7z文件

PS D:\Program Files\Typora> 7z a -t7z .\winmm.dll.creack_typora.7z .\winmm.dll^C#某些目录下执行文件操作需要管理员权限,所以,如果有需要,请通过管理员身份启动shell,然后再启动7zPS D:\Program Files\Typora> 7z a -t7z .\winmm.dll.creack_typora.7z .\winmm.dll7-Zip 21.07 (x64) : Copyright (c) 1999- Igor Pavlov : -12-26Scanning the drive:1 file, 4083712 bytes (3988 KiB)Creating archive: .\winmm.dll.creack_typora.7zAdd new data to archive: 1 file, 4083712 bytes (3988 KiB)Files read from disk: 1Archive size: 3625220 bytes (3541 KiB)Everything is Ok

检查压缩结果

PS D:\Program Files\Typora> ls *win*Directory: D:\Program Files\TyporaModeLastWriteTime Length Name----------------- ------ -----a--- 6/17/ 9:59 AM 4083712  winmm.dll-a--- 6/26/ 7:42 PM 3625220  winmm.dll.creack_typora.7z

权限问题

某些目录下执行文件操作需要管理员权限,所以,如果有需要,请通过管理员身份启动shell,然后再启动7z权限不足示例

Add new data to archive: 1 file, 4083712 bytes (3988 KiB)Error:cannot open file.\winmm.dll.creack_typora.7zAccess is denied. System ERROR:Access is denied.

批量压缩🎈

PS D:\exes\windowsTools> 7z a -t7z .\severial_files.7z .\ScreenToGif.exe .\config.ini7-Zip 22.01 (x64) : Copyright (c) 1999- Igor Pavlov : -07-15Scanning the drive:2 files, 2180811 bytes (2130 KiB)Creating archive: .\severial_files.7zAdd new data to archive: 2 files, 2180811 bytes (2130 KiB)Files read from disk: 2Archive size: 298385 bytes (292 KiB)Everything is Ok

指定压缩类型为zip,批量压缩通配符匹配的文件到同一个包中

PS D:\Program Files\Typora> 7z a -tzip '.\winmm.dll.creack_typora.zip' '.\winmm.*'7-Zip 21.07 (x64) : Copyright (c) 1999- Igor Pavlov : -12-26Scanning the drive:2 files, 7708932 bytes (7529 KiB)Creating archive: .\winmm.dll.creack_typora.zipAdd new data to archive: 2 files, 7708932 bytes (7529 KiB)Files read from disk: 2Archive size: 7372093 bytes (7200 KiB)Everything is Ok

查看压缩包🎈

查看压缩文件信息(压缩包内条目)

例如,使用7z l子命令

7z l .\winmm.dll.creack_typora.zip

PS D:\Program Files\Typora> 7z l .\winmm.dll.creack_typora.zip7-Zip 21.07 (x64) : Copyright (c) 1999- Igor Pavlov : -12-26Scanning the drive for archives:1 file, 7372093 bytes (7200 KiB)Listing archive: .\winmm.dll.creack_typora.zip--Path = .\winmm.dll.creack_typora.zipType = zipPhysical Size = 7372093DateTime Attr Size Compressed Name------------------- ----- ------------ ------------ -------------------------06-17 09:59:45 ....A40837123746557 winmm.dll-06-26 19:42:11 ....A36252203625220 winmm.dll.creack_typora.7z------------------- ----- ------------ ------------ -------------------------06-26 19:42:11 77089327371777 2 files

文件/目录名称指定

建议总是加上引号,防止一些空白字符或者特殊字符引起命令行错误解释!

解压示例

 cxxu   ~/Downloads  ﲍ  100    19:15:36 🚀 7z x '.\PDF-XChange_Editor_Plus_9.2.359.0_Green(1).7z'7-Zip 21.07 (x64) : Copyright (c) 1999- Igor Pavlov : -12-26Scanning the drive for archives:1 file, 142590453 bytes (136 MiB)Extracting archive: .\PDF-XChange_Editor_Plus_9.2.359.0_Green(1).7z

Path = .\PDF-XChange_Editor_Plus_9.2.359.0_Green(1).7zType = 7zPhysical Size = 142590453Headers Size = 11276Method = LZMA:26 BCJ2Solid = +Blocks = 2Everything is OkFolders: 17Files: 547Size: 484316612Compressed: 142590453

linux: 7z/p7zip

不同发行版可用的包名字不同

kali:Kali GNU/Linux Rolling

┌─[cxxu@CxxuWin11] - [/mnt/d/repos/web/webLearn] - [-05-10 02:12:25]└─[0] <git:(main 2852e10✗✱✈) > apt search 7zip[sudo] password for cxxu:Sorting... DoneFull Text Search... Done7zip/kali-rolling,now 21.07+dfsg-4 amd64 [installed]7-Zip file archiver with a high compression ratio

ubuntu 18

┌─[cxxu@cxxuAli] - [~] - [-05-10 02:24:01]└─[1] <> apt search 7zipSorting... DoneFull Text Search... Done....p7zip/bionic,bionic,now 16.02+dfsg-6 amd64 [installed]7zr file archiver with high compression ratiop7zip-full/bionic,bionic,now 16.02+dfsg-6 amd64 [installed]7z and 7za file archivers with high compression ratiop7zip-rar/bionic,bionic 16.02-2 amd64non-free rar module for p7zip

zip系列

7z

7zip支持常见的各种压缩格式:

rar/gzip/bzip2/zip/…7z i可以查看完整列表

PS D:\repos\scripts\jsScripts> 7z x .\archive.zip -ooutput7-Zip 21.07 (x64) : Copyright (c) 1999- Igor Pavlov : -12-26Scanning the drive for archives:1 file, 2387 bytes (3 KiB)Extracting archive: .\archive.zip--Path = .\archive.zipType = zipPhysical Size = 2387Everything is OkFiles: 3Size: 5091Compressed: 2387

Compress-archive

NAMECompress-ArchiveSYNOPSISCreates a compressed archive, or zipped file, from specified files and directories.----- Example 1: Compress files to create an archive file -----$compress = @{Path = "C:\Reference\Draftdoc.docx", "C:\Reference\Images\*.vsd"CompressionLevel = "Fastest"DestinationPath = "C:\Archives\Draft.Zip"}Compress-Archive @compressThe Path parameter accepts specific file names and file names with wildcards, `*.vsd`.The Path uses a comma-separated list to get files from different directories. The compression level is Fastest to reduce processing time. The DestinationPath parameter specifies the location for the `Draft.zip` file. The `Draft.zip` file contains `Draftdoc.docx` and all the files with a `.vsd` extension.-------- Example 2: Compress files using a LiteralPath --------$compress = @{LiteralPath= "C:\Reference\Draft Doc.docx", "C:\Reference\Images\diagram2.vsd"CompressionLevel = "Fastest"DestinationPath = "C:\Archives\Draft.Zip"}Compress-Archive @compressAbsolute path and file names are used because the LiteralPath parameter doesn't acceptwildcards. The Path uses a comma-separated list to get files from different directories. The compression level is Fastest to reduce processing time. The DestinationPath parameter specifies the location for the `Draft.zip` file. The `Draft.zip` file only contains `Draftdoc.docx` and `diagram2.vsd`.-------------Example 3: Compress a directory that includes the root directoryCompress-Archive -Path C:\Reference -DestinationPath C:\Archives\Draft.zip`Compress-Archive` uses the Path parameter to specify the root directory, `C:\Reference`. The DestinationPath parameter specifies the location for the archive file. The `Draft.zip` archive includes the `Reference` root directory, and all its files and subdirectories.Example 4: Compress a directory that excludes the root directoryCompress-Archive -Path C:\Reference\* -DestinationPath C:\Archives\Draft.zip`Compress-Archive` uses the Path parameter to specify the root directory, `C:\Reference` with an asterisk (`*`) wildcard. The DestinationPath * parameter specifies the location for the archive file. The `Draft.zip` archive contains the root directory's filesand subdirectories. The `Reference` root directory is excluded from the archive.---- Example 5: Compress only the files in a root directory ----Compress-Archive -Path C:\Reference\*.* -DestinationPath C:\Archives\Draft.zip`Compress-Archive` uses the Path parameter to specify the root directory, `C:\Reference` with a star-dot-star (` . `) wildcard. The DestinationPath parameter specifies the location for the archive file. The `Draft.zip` archive only contains the `Reference` root directory's files and the root directory is excluded..................

Expand-Archive

NAMEExpand-ArchiveSYNOPSISExtracts files from a specified archive (zipped) file.

examples

NAMEExpand-ArchiveSYNOPSISExtracts files from a specified archive (zipped) file.-------- Example 1: Extract the contents of an archive --------Expand-Archive -LiteralPath 'C:\Archives\Draft[v1].Zip' -DestinationPath C:\ReferenceIn this example, the LiteralPath parameter is used because the filename contains characters that could be interpreted as wildcards.Example 2: Extract the contents of an archive in the current folderExpand-Archive -Path Draftv2.Zip -DestinationPath C:\Reference

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。