zoukankan      html  css  js  c++  java
  • 7zip 命令行模式命令行简介

    命令格式

    7z <command> [<switch>...] <base_archive_name> [<arguments>...]

    7z +操作的名称+  +操作的参数+  +打包文件名+  +要打包的文件+  +其他参数+

    压缩

    a (Add) command

    添加文件到压缩包中

    7z a out1.zip in_dir\ //指定的是目录名

    in_dir \之下的所有的文件和子目录都添加到archive1.zip中。压缩包中的所有文件名都会包含in_dir \前缀。解压时得到的是in_dir目录。压缩的是目录,解压得到的也是目录。

    7z a out1.zip in_dir \* 7z a out1.zip in_dir \ 是一样的。

    7z a out3.zip .\ in_dir \* //指定的是文件名

    in_dir \之下的所有的文件和子目录都添加到out3.zip中。压缩包中的所有文件名都不包含in_dir \前缀。X命令解压时直接得到各个文件和子目录。

    7z a out.zip  -r

    当前目录下的所有文件和子目录打包到out.zip

    压缩后删除原文件

    -sdel (Delete files after compression) switch

    使用这个选项的作用就像是剪切。

    7z a a.7z *.txt -sdel

    moves txt files from disk's directory to a.7z archive.

    使用一个文件列表指定文件名

    List file

    You can supply one or more filenames or wildcards for special list files (files containing lists of files). The filenames in such list file must be separated by new line symbol(s).

    For list files, 7-Zip uses UTF-8 encoding by default. You can change encoding using -scs switch. Multiple list files are supported.

    For example, if the file "listfile.txt" contains the following:

        My programs\*.cpp

        Src\*.cpp

    then the command

        7z a -tzip archive.zip @listfile.txt

    adds to the archive "archive.zip" all "*.cpp" files from directories "My programs" and "Src".

    指定打包文件格式

    7z a -tzip archive.zip *.txt

    adds all *.txt files from current directory to zip archive archive.zip.

    7z t -t7z.split archive.7z.001

    tests all files in archive.7z.001. It also checks that archive is multivolume .7z archive.

    7z x -t# sfxarchive.exe

    extracts sfxarchive.exe in parser mode.

    7z x -tiso archive.iso

    extracts files from archive.iso open as ISO archive.

    7z x -tudf archive.iso

    extracts files from archive.iso open as UDF archive.

    如果没有使用-t{archive_type}指定类型,那么7zip会使用扩展名来决定打包类型。创建新的压缩包,如果没有指定类型,也没有扩展名,会默认创建.7z类型压缩包

    输出压缩包中所有的文件

    l (List contents of archive) command

    Lists contents of archive,包括文件名,以及文件大小、类型等信息。

    命令:7za.exe l out3.zip

    输出

     

    out3.zip里包含的是5文件,而不是两个文件和1一个子目录一个文件中不会包含目录。只不过使用x命令解压的时候可以创建dir1子目录。

    所以 dir1\11.txt 中的dir1 “文件名前缀”,而不是目录名。

    从压缩包中删除文件

    d (Delete) command

    Deletes files from archive.

    Example

    7z d archive.zip *.bak -r

    deletes *.bak files from archive archive.zip.

    解压

    解压有两个命令,e xe命令解压的时候不会保持目录结构,会把所有的文件都解压到目的目录下,不管这些文件是不是位于子文件夹。

    x命令则会保存目录结构。以上面out3.zip为例,

    命令:7za.exe x –oout_dir out3.zip

    out_dir的文件结构:

     

    命令:7za.exe e –oout_dir out3.zip

    out_dir的文件结构:

     

    子目录dir是空目录。

    设置密码

    -p{password} 指定压缩或者解压时的密码。

    7z a archive.7z -psecret -mhe *.txt

    compresses *.txt files to archive.7z using password "secret". Also it encrypts archive headers (-mhe switch), so filenames will be encrypted.

    注意有的参数是和格式关联的,例如zip格式无法设置隐藏文件名对zip格式使用 –mhe 参数就无法成功执行。不同格式适用的不同命令参数见文档。

    7z x archive.zip -psecret

    extracts all files from archive.zip using password "secret".

    计算哈希

    7zip另一项非常有用的功能是计算文件的哈希。使用h (Hash) 命令计算文件的哈希。

    语法格式:h [-scrc{Method}] [files]

    -scrc参数指定计算的方法,支持的方法有 CRC32, CRC64, SHA1, SHA256. 默认是 CRC32.

    Examples

    7z h a.txt

    calculates CRC32 for a.txt.

    7z h -scrcsha256 a.iso

    calculates SHA256 for a.iso.

    7z h *

    calculates CRC32 for all files in current folder and all subfolders.

    Notes

    7-Zip shows hash values for each file, the sum of hash values and the sum that includes all hash values of data and all hash values for filenames.

    7-Zip represents hash values for CRC32 and CRC64 as integer numbers in hex.

    7-Zip represents hash values For SHA1 and SHA256 as sequence of bytes in hex.

  • 相关阅读:
    ubuntu13.04中把ibus中的中文拼音输入设为默认
    PHP中获取星期的几种方法
    linux 指令(经常更新)
    手机禁止浏览器往下拉
    Linux常用命令大全
    flask之SQLAlchemy
    【原创】微服务为什么一定要用docker
    flask3
    nginx+uWSGI+django+virtualenv+supervisor发布web服务器
    flask之jinji2模板介绍
  • 原文地址:https://www.cnblogs.com/robotech/p/9801286.html
Copyright © 2011-2022 走看看