Linux如何带压缩密码的7z,Linux 压缩和解压 7z
在上一篇教程 Linux压缩和解压rar 中写了 rar 的压缩和解压,这里继续来写 7z 的压缩和解压。7z 是现在主流的一种压缩格式,它拥有极高的压缩比,我做过一个测试,用 rar 和 7z 压缩同一个文件,都选择最高质量,最终经过 7z 压缩的文件体积确实要比 rar 小一些,而且 7z 是开源免费的,现在很多压缩工具也都能解压 7z。
我用来演示的 Linux 版本是 CentOS7,因为 CentOS 的 yum 没有 p7zip,所以只能手动下载 rpm 安装。
下载 p7zip:wget https://www.mirrorservice.org/sites/dl.fedoraproject.org/pub/epel/7/x86_64/Packages/p/p7zip-16.02-10.el7.x86_64.rpm
下载 p7zip-plugins:wget https://www.mirrorservice.org/sites/dl.fedoraproject.org/pub/epel/7/x86_64/Packages/p/p7zip-plugins-16.02-10.el7.x86_64.rpm
安装 p7zip:rpm -ivh p7zip-16.02-10.el7.x86_64.rpm
安装 p7zip-plugins:rpm -ivh p7zip-plugins-16.02-10.el7.x86_64.rpm
如果要更详细的了解 rpm 包管理可以看 Linux rpm包管理,安装完成后输入 7z,如果出现帮助信息说明安装成功。
如果是 Ubuntu 这一类系统的话,直接输入下面的两条命令自动下载安装:apt-get install p7zip
apt-get install p7zip-full
关于使用方法 CentOS 和 Ubuntu 都是一样的。
压缩
压缩文件: 7z a 压缩包名 要压缩的文件名 ,下面把 1.php 压缩为 1.7z:[root@localhost home]# 7z a 1.7z 1.php
7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=zh_CN.UTF-8,Utf16=on,HugeFiles=on,64 bits,1 CPU Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz (506E3),ASM,AES-NI)
Scanning the drive:
1 file, 35 bytes (1 KiB)
Creating archive: 1.7z
Items to compress: 1
Files read from disk: 1
Archive size: 153 bytes (1 KiB)
Everything is Ok
下面把 1.php 和 2.php 压缩为 file.7z:[root@localhost home]# 7z a file.7z 1.php 2.php
7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=zh_CN.UTF-8,Utf16=on,HugeFiles=on,64 bits,1 CPU Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz (506E3),ASM,AES-NI)
Scanning the drive:
2 files, 224 bytes (1 KiB)
Creating archive: file.7z
Items to compress: 2
Files read from disk: 2
Archive size: 318 bytes (1 KiB)
Everything is Ok
下面把 dir 目录压缩为 dir.7z:[root@localhost home]# 7z a dir.7z dir
7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=zh_CN.UTF-8,Utf16=on,HugeFiles=on,64 bits,1 CPU Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz (506E3),ASM,AES-NI)
Scanning the drive:
1 folder, 2 files, 224 bytes (1 KiB)
Creating archive: dir.7z
Items to compress: 3
Files read from disk: 2
Archive size: 338 bytes (1 KiB)
Everything is Ok
给压缩包添加文件: 7z u 压缩包名 要添加的文件名 ,下面把 2.php 添加到 1.7z:[root@localhost home]# 7z u 1.7z 2.php
7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=zh_CN.UTF-8,Utf16=on,HugeFiles=on,64 bits,1 CPU Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz (506E3),ASM,AES-NI)
Open archive: 1.7z
--
Path = 1.7z
Type = 7z
Physical Size = 153
Headers Size = 114
Method = LZMA2:12
Solid = -
Blocks = 1
Scanning the drive:
1 file, 189 bytes (1 KiB)
Updating archive: 1.7z
Items to compress: 1
Files read from disk: 1
Archive size: 336 bytes (1 KiB)
Everything is Ok
删除压缩包内的文件: 7z d 压缩包名 要删除的文件名 ,下面删除 1.7z 中的 2.php:[root@localhost home]# 7z d 1.7z 2.php
7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=zh_CN.UTF-8,Utf16=on,HugeFiles=on,64 bits,1 CPU Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz (506E3),ASM,AES-NI)
Open archive: 1.7z
--
Path = 1.7z
Type = 7z
Physical Size = 336
Headers Size = 161
Method = LZMA2:12
Solid = -
Blocks = 2
Updating archive: 1.7z
Items to compress: 0
Files read from disk: 0
Archive size: 153 bytes (1 KiB)
Everything is Ok
加密压缩: 7z a -p 压缩包名 要压缩的文件名 ,执行命令后会提示输入密码,输入密码的时候终端不会显示任何内容,下面把 1.php 加密压缩为 1.7z:[root@localhost home]# 7z a -p 1.7z 1.php
7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=zh_CN.UTF-8,Utf16=on,HugeFiles=on,64 bits,1 CPU Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz (506E3),ASM,AES-NI)
Scanning the drive:
1 file, 35 bytes (1 KiB)
Creating archive: 1.7z
Items to compress: 1
Enter password (will not be echoed):
Verify password (will not be echoed) :
Files read from disk: 1
Archive size: 178 bytes (1 KiB)
Everything is Ok
解压
把文件解压到当前目录: 7z e 压缩包名 ,下面解压 1.7z:[root@localhost home]# 7z e 1.7z
7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=zh_CN.UTF-8,Utf16=on,HugeFiles=on,64 bits,1 CPU Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz (506E3),ASM,AES-NI)
Scanning the drive for archives:
1 file, 153 bytes (1 KiB)
Extracting archive: 1.7z
--
Path = 1.7z
Type = 7z
Physical Size = 153
Headers Size = 114
Method = LZMA2:12
Solid = -
Blocks = 1
Everything is Ok
Size: 35
Compressed: 153
查看压缩包内的文件信息: 7z l 压缩包名 ,下面查看 1.7z 中的文件信息:[root@localhost home]# 7z l 1.7z
7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=zh_CN.UTF-8,Utf16=on,HugeFiles=on,64 bits,1 CPU Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz (506E3),ASM,AES-NI)
Scanning the drive for archives:
1 file, 240 bytes (1 KiB)
Listing archive: 1.7z
--
Path = 1.7z
Type = 7z
Physical Size = 240
Headers Size = 158
Method = LZMA2:12
Solid = -
Blocks = 2
Date Time Attr Size Compressed Name
------------------- ----- ------------ ------------ ------------------------
2019-02-24 10:41:29 ....A 35 39 1.php
2019-02-24 12:25:13 ....A 41 43 2.php
------------------- ----- ------------ ------------ ------------------------
2019-02-24 12:25:13 76 82 2 files
下面是 p7zip 常用的一些参数:参数说明a压缩文件
d删除压缩包内的文件
e把文件解压到当前目录
h计算文件的哈希值
i显示有关支持格式的信息
l列出压缩包内的内容
m重命名压缩包内的文件
t测试压缩包的完整性
u添加文件到压缩包
p7zip 除了上面列出的参数外还有很多可选的选项,下面是 p7zip 的帮助说明:
a : Add files to archive
b : Benchmark
d : Delete files from archive
e : Extract files from archive (without using directory names)
h : Calculate hash values for files
i : Show information about supported formats
l : List contents of archive
rn : Rename files in archive
t : Test integrity of archive
u : Update files to archive
x : eXtract files with full paths
-- : Stop switches parsing
-ai[r[-|0]]{@listfile|!wildcard} : Include archives
-ax[r[-|0]]{@listfile|!wildcard} : eXclude archives
-ao{a|s|t|u} : set Overwrite mode
-an : disable archive_name field
-bb[0-3] : set output log level
-bd : disable progress indicator
-bs{o|e|p}{0|1|2} : set output stream for output/error/progress line
-bt : show execution time statistics
-i[r[-|0]]{@listfile|!wildcard} : Include filenames
-m{Parameters} : set compression Method
-mmt[N] : set number of CPU threads
-o{Directory} : set Output directory
-p{Password} : set Password
-r[-|0] : Recurse subdirectories
-sa{a|e|s} : set Archive name mode
-scc{UTF-8|WIN|DOS} : set charset for for console input/output
-scs{UTF-8|UTF-16LE|UTF-16BE|WIN|DOS|{id}} : set charset for list files
-scrc[CRC32|CRC64|SHA1|SHA256|*] : set hash function for x, e, h commands
-sdel : delete files after compression
-seml[.] : send archive by email
-sfx[{name}] : Create SFX archive
-si[{name}] : read data from stdin
-slp : set Large Pages mode
-slt : show technical information for l (List) command
-snh : store hard links as links
-snl : store symbolic links as links
-sni : store NT security information
-sns[-] : store NTFS alternate streams
-so : write data to stdout
-spd : disable wildcard matching for file names
-spe : eliminate duplication of root folder for extract command
-spf : use fully qualified file paths
-ssc[-] : set sensitive case mode
-ssw : compress shared files
-stl : set archive timestamp from the most recently modified file
-stm{HexMask} : set CPU thread affinity mask (hexadecimal number)
-stx{Type} : exclude archive type
-t{Type} : Set type of archive
-u[-][p#][q#][r#][x#][y#][z#][!newArchiveName] : Update options
-v{Size}[b|k|m|g] : Create volumes
-w[{path}] : assign Work directory. Empty path means a temporary directory
-x[r[-|0]]{@listfile|!wildcard} : eXclude filenames
-y : assume Yes on all queries
到这里关于 Linux 的压缩基本上就已经写完了。
版权声明:本文为原创文章,版权归 Mr. Ma's Blog 所有,转载请联系博主获得授权。
如果对本文有什么问题或疑问都可以在评论区留言,我看到后会尽量解答。
Linux如何带压缩密码的7z,Linux 压缩和解压 7z相关推荐
- dd指令打包iso文件 linux_从零开始学Linux运维|33.文件的打包压缩和解压
linux下打包文件常用的是tar命令 tar [选项] [文件] 常用参数 -c 创建压缩包-x 解压压缩包-t 查看压缩包内容-f 指定压缩包名字(压缩解压必选项)-v 显示所有过程-z gzip ...
- ubuntu18.04上使用7z分卷压缩和解压
安装7z工具 sudo apt-get install p7zip-full 压缩解压 压缩 基础用法 # 7za a [目标文件].7z [原文件/文件夹] 7za a -t7z -r file_n ...
- linux带密码解压密码,linux 下文件加密压缩和解压的方法
方法一:用tar命令 对文件加密压缩和解压 压缩: [html] view plain copy tar -zcf - filename |openssl des3 -salt -k password ...
- Linux的zip压缩文件压缩和解压
Linux的zip压缩文件压缩和解压 <Linux一线运维实战>清华大学出版社(即将出版) 通常,系统中的文件的可以被直接打开的,这就难免文件的内容被查看.另外,对于要归档保存的(压缩)文 ...
- linux压缩100天以上的文件,如何提高几十甚至上百G文件的压缩和解压效率
如何提高几十甚至上百G文件的压缩和解压效率 (2012-06-05 02:21:35) 标签: 的 如何 杂谈 如何提高几十甚至上百G文件的压缩和解压效率需求: 有几十.上百G的文件需要压缩.解压.前 ...
- 【Linux】文件的压缩和解压
欢迎来到博主 Apeiron 的博客,祝您旅程愉快 ! 时止则止,时行则行.动静不失其时,其道光明. 目录 1.压缩格式 2.压缩软件 3.tar 命令简介 4.tar 命令压缩 5.总结 1.压 ...
- Linux压缩和解压命令:tar,gzip,zip(unzip),rar
很多大型文件或者数据从服务器上传或者下载的时候都需要打包和压缩解压,这时候知道压缩和解压的各种命令是很有必要的. 常见的压缩文件后缀名有.tar.gz,.gz,.zip和.rar,下面来看看在Linu ...
- linux为什么用tar压缩,linux下tar压缩和解压命令用法详解
linux下tar压缩和解压命令用法详解 2017-03-25 14:06 分享人:老牛 将/usr/local/test目录下所有文件仅打包,不压缩到 /usr/local/auto_bak/目下 ...
- Linux各类压宿包的压缩和解压方法
Linux各类压宿包的压缩和解压方法 tar格式 解包: tar xvf FileName.tar 打包: tar cvf FileName.tar DirName gz格式 解压1: gunzip ...
最新文章
- (干货)微信小程序转发好友
- SQL SERVER中求上月、本月和下月的第一天和最后一天[转]
- 报错提示:java.lang.IllegalArgumentException: Target must not be null
- Python 之vim编写python自动补全
- ubi-partman failed with exit code 141
- 根据测试路径自动生成测试用例_自拍教程75Python 根据测试用例选择测试资源
- Python 多种算法模型对比
- PHP页面间参数传递的四种方式
- 开源分布式中间件 DBLE 快速入门指南
- 各种排序算法及其实现总结
- 软件配置管理(三)软件配置管理核心功能
- C#中一些格式的转换
- Mybatis(10)properties标签的使用及细节,typeAliases和package标签
- leancloud上传php源码部署,部署灵动云商到LeanCloud[图解]
- Lorenz混沌系统建模与电路仿真实现
- LR 类分析方法总结
- qq邮箱怎么qq找不到服务器,qq邮箱登录手机版网页 求高手 QQ邮箱登不上去 显示找不到服务器15?请问我咋用不...
- 关于勾股数的规律及证明
- c++语言程序中,main()函数必须放在程序开始的部分,C++多选题(附答案)
- C语言如何打开shx文件,shx文件怎么打开?Win7打开shx文件的操作方法