因工作中要对数据打包,顺便研究了下WinRAR的命令行模式,自己写了些例子,基本用法如下:
测试压缩文件准备:文件夹test_data,内部包含子文件夹,分别存放了一些*.log和*.txt文件。
测试代码如下:
1 rem 压缩全部文件,按类型压缩,zip打包
2 WinRAR.exe a num_all.zip .\test_data\
3 WinRAR.exe a num_txt.zip .\test_data\num*.txt
4 WinRAR.exe a num_log.zip .\test_data\num*.log
5 6 rem 压缩全部文件,按类型压缩,rar打包
7 WinRAR.exe a num_all.rar .\test_data\
8 WinRAR.exe a num_txt.rar .\test_data\num*.txt
9 WinRAR.exe a num_log.rar .\test_data\num*.log
10
11 rem 默认压缩根目录,递归处理子文件夹使用 -r
12 WinRAR.exe a -r num_all_tg.zip .\test_data\*.*
13 WinRAR.exe a -r num_all_txt.zip .\test_data\*.txt
14 WinRAR.exe a -r num_all_log.rar .\test_data\*.log
15
16
17 rem 添加注释,注释从一个txt文件读取,txt文件名info.txt
18 WinRAR.exe c -zinfo.txt num_all.zip
19 WinRAR.exe c -zinfo.txt num_all.rar
20
21 rem 从压缩包中读取注释,写入到read.txt文件,默认ASCII,参数-scuc表示unicode
22 WinRAR.exe cw num_all.zip read1_ASCII.txt
23 WinRAR.exe cw num_all.rar read2_ASCII.txt
24 WinRAR.exe cw -scuc num_all.rar read_unicode.txt
25 26 rem 从压缩包中删除制定文件
27 WinRAR.exe d num_all_tg.zip *.log
28
29 rem 解压到当前目录下,不包含压缩包内的路径
30 WinRAR.exe e num_all_tg.zip
31 rem 解压到制定目录下,不包含压缩包内的路径
32 WinRAR.exe e num_all_tg.zip .\test_d2
33 rem 解压到当前目录下,只解压制定类型的文件
34 WinRAR.exe e num_all_tg.zip *.log
35
36 rem 给压缩包内的文件重命名
37 WinRAR.exe rn num_all_tg.zip num(1).txt num(1).bak num(2).txt num(2).bak
38 WinRAR.exe rn num_all.rar *.txt *.bak
39 40 rem 使用压缩包捏的绝对路径解压
41 WinRAR.exe x num_all_tg.zip
42 rem 使用压缩包捏的绝对路径解压,解压指定类型文件
43 WinRAR.exe x num_all_tg.zip *.log
44 rem 使用压缩包捏的绝对路径解压,解压指定类型文件,并解压到指定文件夹
45 WinRAR.exe x num_all_tg.zip *log .\new_data\
以上为winrar的基本压缩,解压命令。
关于winrar 的开关选项,以后有空再研究整理。
备注:WinRAR.exe为安装完后,从安装目录将主程序winRAR.exe拷贝出来即可,该程序是独立可运行的。
以下为winRAR的命令帮助原文:
Alphabetic commands list
a | add files to an archive |
c | add an archive comment |
ch | change archive parameters |
cv | convert archives |
cw | write an archive comment to file |
d | delete files from an archive |
e | extract files from an archive, ignoring paths |
f | freshen files within an archive |
i | find string in archives |
k | lock an archive |
m | move files and folders to an archive |
r | repair a damaged archive |
rc | reconstruct missing volumes |
rn | rename archived files |
rr[N] | add data recovery record |
rv[N] | create recovery volumes |
s[name] | convert an archive to a self-extracting type |
s- | remove SFX module |
t | test archive files |
u | update files within an archive |
x | extract files from an archive with full paths |
Winrar的命令行模式程序在安装目录下的 rar.exe (打包压缩程序),unrar.exe(解压缩程序),以我安装的winrar5.3为例,帮助文档如下:
..\WinRAR\Rar.exe:
1 RAR 5.30 beta 2 版权所有 (C) 1993-2015 Alexander Roshal
2 试用版本 输入 RAR -? 以获得帮助
3 4 用法:rar <命令> -<参数 1> -<参数 N> <压缩文件> <文件...>
5 <@列表文件...> <解压路径\>
6 7 <命令>
8 a 添加文件到压缩文件
9 c 添加压缩文件注释
10 ch 更改压缩文件参数
11 cw 将压缩文件注释写入文件
12 d 从压缩文件中删除文件
13 e 提取文件无需压缩文件的路径
14 f 更新压缩文件里的文件
15 i[par]=<str> 查找压缩文件中的字符串
16 k 锁定压缩文件
17 l[t[a],b] 列出压缩文件内容 [technical[all], bare]
18 m[f] 移动到压缩文件 [仅文件]
19 p 打印文件到 stdout
20 r 修复压缩文件
21 rc 重建丢失的分卷
22 rn 重命名已压缩文件
23 rr[N] 添加数据恢复记录
24 rv[N] 创建恢复分卷
25 s[name|-] 转换压缩文件为自解压或自解压转换为压缩文件
26 t 测试压缩文件
27 u 更新压缩文件中的文件
28 v[t[a],b] 详细列出压缩文件内容 [technical[all],bare]
29 x 使用完整路径提取文件
30
31 <参数>
32 - 停止参数扫描
33 @[+] 禁用 [启用] 文件列表
34 ac 压缩或解压后清除存档属性
35 ad 添加压缩文件名到目标路径
36 ag[格式] 使用当前日期生成压缩文件名
37 ai 忽略文件属性
38 ao 添加具有压缩属性的文件
39 ap<格式> 添加路径到压缩文件中
40 as 同步压缩文件内容
41 c- 禁用注释显示
42 cfg- 禁用读取配置
43 cl 转换名称到小写
44 cu 转换名称到大写
45 df 压缩文件后删除原来的文件
46 dh 打开已共享文件
47 dr 删除文件到回收站
48 ds 对固实压缩文件禁用名称排序
49 dw 压缩文件后清除文件
50 e[+]<attr> 设置文件排除和包含属性
51 ed 不要添加空目录
52 en 不要放置 '压缩文件结束' 区块
53 ep 从名称里排除路径
54 ep1 从名称里排除基目录
55 ep2 扩展路径到完整路径
56 ep3 扩展路径为完整路径包括驱动器盘符
57 f 更新文件
58 hp[password] 加密文件数据和文件头
59 ht[b|c] 为文件校验和选择哈希类型 [BLAKE2,CRC32]
60 id[c,d,p,q] 禁用信息
61 ieml[addr] 通过电邮发送压缩文件
62 ierr 发送所有消息到 stderr
63 ilog[name] 记录错误到文件(仅注册版本)
64 inul 禁用所有消息
65 ioff 完成操作后关闭电脑
66 isnd 启用声音
67 k 锁定压缩文件
68 kb 保留损坏的已解压缩文件
69 log[f][=name] 将名称写入日志文件
70 m<0..5> 设置压缩级别(0-存储...3-默认...5-最大)
71 ma[4|5] 指定压缩格式的一个版本
72 mc<par> 设置高级压缩参数
73 md<n>[k,m,g] 字典大小显示为 KB, MB 或 GB
74 ms[ext;ext] 指定要存储的文件类型
75 mt<threads> 设置线程数
76 n<file> 额外的包含过滤器的文件
77 n@ 从 stdin 读取额外的过滤器掩码
78 n@<list> 从列表文件读取额外的过滤器掩码
79 o[+|-] 设置覆盖模式
80 oc 设置 NTFS 压缩属性
81 oh 将硬链接保存为链接而非文件
82 oi[0-4][:min] 将完全相同的文件保存为引用
83 ol[a] 将符号链接作为链接处理 [绝对路径]
84 or 自动重命名文件
85 os 保存 NTFS 流
86 ow 保存或恢复文件所有者和组
87 p[password] 设置密码
88 p- 不查询密码
89 qo[-|+] 添加快速打开信息 [无|强制]
90 r 递归子目录
91 r- 禁用递归
92 r0 仅为通配符名称递归子目录
93 ri<P>[:<S>] 设置优先级 (0-默认,1-最小..15-最大) 和睡眠时间为 ms
94 rr[N] 添加数据恢复记录
95 rv[N] 创建恢复分卷
96 s[<N>,v[-],e] 创建固实压缩文件
97 s- 禁用固实压缩文件
98 sc<chr>[obj] 指定字符集
99 sfx[name] 创建自解压文档
100 si[name] 从标准输入 (stdin) 读取数据
101 sl<size> 处理小于指定大小的文件
102 sm<size> 处理大于指定大小的文件
103 t 压缩文件后测试文件
104 ta<date> 处理在 <日期> 之后修改过的文件,以 YYYYMMDDHHMMSS 格式
105 tb<date> 处理在 <日期> 之前修改过的文件,以 YYYYMMDDHHMMSS 格式
106 tk 保存原来的压缩文件时间
107 tl 设置压缩文件时间为最新的文件
108 tn<time> 处理比 <时间> 较新的文件
109 to<time> 处理比 <时间> 较旧的文件
110 ts<m,c,a>[N] 保存或恢复文件时间(修改,创建,访问)
111 u 更新文件
112 v<size>[k,b] 创建分卷大小为=<size>*1000 [*1024, *1]
113 vd 创建分卷之前清除磁盘内容
114 ver[n] 文件版本控制
115 vn 使用旧式的分卷命名方案
116 vp 创建每个分卷之前暂停
117 w<path> 指定工作目录
118 x<file> 排除指定的文件
119 x@ 读取文件名以从 stdin 排除
120 x@<list> 排除指定列表文件里列出的文件
121 y 对所有询问假定选择“是”
122 z[file] 从文件读取压缩文件注释
..\WinRAR\unRar.exe:
UNRAR 5.30 beta 2 免费软件 版权所有 (C) 1993-2015 Alexander Roshal
用法:unrar <命令> -<参数 1> -<参数 N> <压缩文件> <文件...> <@列表文件...> <解压路径\>
评论(0)