Linux下rar,unrar命令详解
rar和unrar的用法
rar   <命令> -<选项1> ….-<选项N> < 操作文档> <文件…> <@文件列表…> <解压路径>
unrar <命令> -<选项1> ….-<选项N> < 操作文档> <文件…> <@文件列表…> <解压路径>
压缩rar命令
a添加文件到压缩文件c添加压缩文件注释cf添加文件注释cw写入压缩文件注释到文件d删除压缩文件中的文件e解压压缩文件到当前目录f刷新压缩文件中的文件i[参数]=<串>在压缩文件中查找字符串k锁定压缩文件l[t,b]列出压缩文件[技术信息,简洁]m[f]移动到压缩文件[仅对文件]p打印文件到标准输出设备r修复压缩文件rc重建丢失的卷rn重命名压缩文件rr[N]添加数据恢复记录rv[N]创建恢复卷s[名字|-]转换压缩文件为自解压格式或转换回压缩文件t测试压缩文件u更新压缩文件中的文件v[t,b]详细列出压缩文件[技术信息,简洁]x用绝对路径解压文件
压缩rar选项
-Stop switches scanningadAppend archive name to destination pathag[format]Generate archive name using the current dateap<path>Set path inside archiveasSynchronize archive contentsavPut authenticity verification (registered versions only)av-Disable authenticity verification checkc-Disable comments showcfg-Disable read configurationclConvert names to lower casecuConvert names to upper casedfDelete files after archivingdhOpen shared filesdsDisable name sort for solid archivedwWipe files after archivinge[+]<attr>Set file exclude and include attributesedDo not add empty directoriesenDo not put 'end of archive' blockepExclude paths from namesep1Exclude base directory from namesep3Expand paths to full including the drive letterfFreshen fileshp[password]Encrypt both file data and headersid[c,d,p,q]Disable messagesierrSend all messages to stderrilog[name]Log errors to file (registered versions only)inulDisable all messagesisndEnable soundkLock archivekbKeep broken extracted filesm<0..5>Set compression level (0-store...3-default...5-maximal)mc<par>Set advanced compression parametersmd<size>Dictionary size in KB (64,128,256,512,1024,2048,4096 or A-G)ms[ext;ext]Specify file types to storen<file>Include only specified filen@Read file names to include from stdinn@<list>Include files in specified list fileo[+|-]Set the overwrite modeolSave symbolic links as the link instead of the fileorRename files automaticallyowSave or restore file owner and groupp[password]Set passwordp-Do not query passwordrRecurse subdirectoriesr0Recurse subdirectories for wildcard names onlyrr[N]Add data recovery recordrv[N]Create recovery volumess[<N>,v[-],e]Create solid archives-Disable solid archivingsc<chr>[obj]Specify the character setsfx[name]Create SFX archivesi[name]Read data from standard input (stdin)sl<size>Process files with size less than specifiedsm<size>Process files with size more than specifiedtTest files after archivingta<date>Process files modified afterin YYYYMMDDHHMMSS format tb<date>Process files modified beforein YYYYMMDDHHMMSS format tkKeep original archive timetlSet archive time to latest filetn<time>Process files newer thanto<time>Process files older thants<m,c,a>[N]Save or restore file time (modification, creation, access)uUpdate filesvCreate volumes with size autodetection or list all volumesv<size>[k,b]Create volumes with size=*1000 [*1024, *1] ver[n]File version controlvnUse the old style volume naming schemevpPause before each volumew<path>Assign work directoryx<file>Exclude specified filex@Read file names to exclude from stdinx@<list>Exclude files in specified list fileyAssume Yes on all queriesz[file]Read archive comment from file
解压unrar命令
e解压文件到当前目录l[t,b]列出压缩文档信息[technical, bare]p打印文件到标准输出t测试压缩我俄当v[t,b]列出压缩文档的详细信息[technical,bare]x解压文件到完整路径
解压unrar选项
-Stop switches scanningadAppend archive name to destination pathap<path>Set path inside archiveav-Disable authenticity verification checkc-Disable comments showcfg-Disable read configurationclConvert names to lower casecuConvert names to upper casedhOpen shared filesepExclude paths from namesep3Expand paths to full including the drive letterfFreshen filesid[c,d,p,q]Disable messagesierrSend all messages to stderrinulDisable all messageskbKeep broken extracted filesn<file>Include only specified filen@Read file names to include from stdinn@<list>Include files in specified list fileo[+|-]Set the overwrite modeorRename files automaticallyowSave or restore file owner and groupp[password]Set passwordp-Do not query passwordrRecurse subdirectoriessl<size>Process files with size less than specifiedsm<size>Process files with size more than specifiedta<date>Process files modified afterin YYYYMMDDHHMMSS format tb<date>Process files modified beforein YYYYMMDDHHMMSS format tn<time>Process files newer thanto<time>Process files older thants<m,c,a>[N]Save or restore file time (modification, creation, access)uUpdate filesvList all volumesver[n]File version controlvpPause before each volumex<file>Exclude specified filex@Read file names to exclude from stdinx@<list>Exclude files in specified list fileyAssume Yes on all queries
具体示例
- 
rar a file file.ext
如果file.rar不存在将创建file.rar文件;如果file.rar压缩包中已有file.ext,将更新压缩包中的file.ext; - 
rar a -r -v2000 -s -sfx -rr file
从当前文件夹和子文件夹压缩全部文件成为 2000000 字节大小、固实的、分卷自解压文件 file.part1.exe,file.part2.rar,file.part3.rar 等,并在每一个分卷中添加恢复记录;将命令a换成命令m可将文件压缩后删除 - 
rar x Fonts *.ttf
会从压缩文件解压 *.ttf 字体文件到当前文件夹,但下面命令:
rar x Fonts *.ttf NewFonts
会从压缩文件解压 *.ttf 字体文件到文件夹 NewFont - 
rar a -pZaBaToAd -r secret games\*.*
使用密码 ZaBaToAd 来将文件夹“games”的内容添加到压缩文件“secret” - 
rar a -r a.rar a/
递归的将a/下所有东西压缩到a.rar - 
rar a test.rar file1.txt
若test.rar文件不存在,则打包file1.txt文件成test.rar - 
`rar c test.rar
对操作文档添加说明注释 - 
rar cw test.rar comment.txt
将文档注释写入文件 - 
rar d test.rar file1.txt
从文档中删除文件 - 
rar e test.rar
将文件解压到当前目录
注:用e解压的话,不仅原来的file1.txt和file2.txt被解压到当前目录,就连dir1里面的所有文件
也被解压到当前目录下,不能保持压缩前的目录结构,如果想保持压缩前的目录结构,用x解压 - 
rar k test.rar
锁定文档,锁定文档后,该文档就无法进行任何更新操作了 - 
rar r test.rar
当rar文件有问题时,可以尝试用该命令进行修复 - 
rar s test.rar
转换文档成自解压文档
会生成一个test.sfx的可执行文档,运行它的效果就相当于rar x test.rar,
适合于向没有rar的用户传输文件 - 
rar t test.rar
检测test.rar的完整性,一般压缩完大型文件准备传输前最好用这个命令来确保文件的正确性 - 
rar x test.rar
带路径解压文档中内容到当前目录,这样解压的话,dir1就会保持原来的目录结构 - 
rar a -cl test.rar FILe.txt
FILe.txt在添加进test.rar之后,变为file.txt - 
rar a -df test.rar file1.txt file2.txt dir1
将file1.txt,file2.txt,dir1压缩到test.rar中之后,删除源文件 - 
rar a -ed test.rar dir1
添加dir1到test.rar中时,不对空目录进行操作 - 
rar e -ed test.rar
解压test.rar时,不生成空目录 - 
rar a -m0 test.rar dir1 dir2
将dir1,dir2打包存储到test.rar,不进行实质上的压缩(速度奇快,适合于对无甚可压的文件进行操作比如avi,jpg等)m<0..5> 设定压缩比等级(0-存储,3-默认,5-最大) - 
rar a -m5 test.rar *.txt *.bmp
将当前目录下的txt文件和bmp文件打包压缩到test.rar中,使用最大压缩比(最慢) - 
rar a -m5 -ms avi;jpg;jpeg test.rar /home
将home目录下所有目录和文件归档到test.rar,采用最大压缩,但avi,jpg,jpeg文件不进行压缩
(只是打包进test.rar,因为这些文件即使用最大压缩也压不了多少,不如直接打包节省时间) - 
rar x -o- test.rar
o+ 覆盖已有文件
o- 不覆盖已有文件
解压test.rar文件,但是如果碰到以存在的文件则不覆盖 - 
rar a test.rar *.txt -p prettygirl
压缩文件设定密码为prettygirl,解压时无密码无法进行操作
如果觉得明码密码太过暴露,可以使用
rar a test.rar *.txt -p
则rar程序会询问你要使用什么密码,不回显 - 
rar a test.rar /home -t
压缩完毕后进行检验,如果有问题则报错