压缩命令之rar、unrar

rar是一个商业软件,但有时候我们需要在linux 下做批量操作,这时候就需要用到命令,下面我们来说说rar、unrar在命令行下的一些操作,希望对你们有所帮助!

一、安装winrar

winrar从v5开始,只提供window和linux版的,而linux版只提供二进制文件,这样我们就可以直接在命令行进行操作。比如在terminal下压缩文件a.xls到文件 a.xls.rar中,语法如下:

rar a ‘a.xls.rar’ ‘a.xls’ #

使用起来非常简单,类似linux下的tar

参考:

其他常用的rar语法:

1
rar -p a target.rar files.. # 带密码压缩rar,会询问2次密码

二、配置

2.1 key配置

WinRAR, RAR for Unix and OS X now use the same registration key format, so you can use the same key with current WinRAR and RAR versions for all mentioned platforms.
so Yes, it is possible.

Further, it also states where to copy the key:

If you use RAR/Unix and RAR for OS X, you should copy rarreg.key to your home directory or to one of the following directories: /etc, /usr/lib, /usr/local/lib, /usr/local/etc. You may rename it to .rarreg.key or .rarregkey, if you wish, but rarreg.key is also valid.

参考:https://superuser.com/questions/1089501/how-to-transfer-winrar-key-to-linux

分享我的rarreg.key:

1
2
3
4
5
6
7
8
9
10
11
RAR registration data
Admin
Unlimited Company License
UID=1d7426b0b166c91c21ab
641221225021abd0925f7c70456ecd71f724a7f5a00b0a0f7d19ee
45c5e20951dae2857c2960fce6cb5ffde62890079861be57638717
7131ced835ed65cc743d9777f2ea71a8e32c7e593cf66794343565
b41bcf56929486b8bcdac33d50ecf773996076c281ccab247f6153
ed97a3e4a4cb9bffbf35ed364a5cc6908fd2cdc84e9f53a33cf463
9d85cd75291397987399f5159745c84654dfd11e471ec7a360b22a
bbaf66105e62e8afa2d5d154b0c164b1f5377d2975460025531542

然后复制或添加软链接到配置目录,你可能要执行这样的命令:

1
ln -sfv /workspace/bin/winrar/rarreg.key /usr/local/etc/rarreg.key # mac