在Linux或者UNIX下打开RAR文件/提取RAR文件
时间:2020-01-09 10:42:50 来源:igfitidea点击:
如何在Linux或者UNIX或者macOS X操作系统下打开rar存档文件? RAR文件采用压缩存档格式,如果您已经从Internet下载了rar文件,则需要解压缩或者解压缩它们(提取rar文件)。 RAR是由Eugene Roshal开发的用于数据压缩和归档的专有文件格式。 用于提取这些文件的命令称为unrar。
默认情况下,unrar不会安装在Linux,FreeBSD或者UNIX之类的操作系统上。
您可以在apt-get或者yum命令的帮助下安装unrar命令。
安装unrar命令
如果您使用的是Debian或者Ubuntu Linux,则需要输入apt-get命令或者apt命令,如下所示以安装unrar程序:
$ sudo apt-get install unrar
或者
$ sudo apt install unrar
如果您使用的是CentOS/RHEL
,请按以下方式使用yum命令(有关更多信息,请参见下面的讨论):
# yum install unrar
如果使用的是Fedora Linux,请使用dnf命令:
$ sudp dnf install unrar
如果您使用的是FreeBSD Unix,请使用pkg命令:
# pkg install unrar
如果您使用的是OpenBSD Unix,请使用pkg_add命令:
# pkg_add -v unrar
如果您使用的是macOS
Unix和Homebrew,请使用brew命令:
$ brew install unrar
如果以上任何一种方法不适用于您的Unix/Linux版本,请从rarlab官方网站下载二进制软件包:
$ cd /tmp ## 32 bit linux ## $ wget https://www.rarlab.com/rar/rarlinux-5.5.0.tar.gz
或者对于64位Linux版本:
$ wget http://www.rarlab.com/rar/rarlinux-x64-5.3.b4.tar.gz
接下来,使用tar命令解压缩文件,执行:
$ tar -zxvf rarlinux-*.tar.gz
unrar和rar命令都位于rar子目录中。
只需cd到rar目录,执行:
$ cd rar $ ./unrar
现在将rar和unrar文件复制到/usr/local/bin目录,执行:
$ sudo cp rar unrar /usr/local/bin
如何使用unrar命令
unrar命令支持各种选项,以下是提取文件所需的常用选项。
解压缩rar(解压)文件
要将file.rar文件解压缩到当前目录,请执行:
$ unrar e file.rar
输出示例:
UNRAR 5.50 freeware Copyright (c) 1993-2016 Alexander Roshal Extracting from file.rar Extracting adduser.conf OK Extracting apg.conf OK Extracting appstream.conf OK Extracting brltty.conf OK Extracting ca-certificates.conf OK Extracting sensors3.conf OK Extracting sysctl.conf OK All OK
在rar存档中列出(l)文件:
$ unrar l file.rar
列出存储在rar存档中的所有文件
用完整路径类型命令提取(x)个文件:
$ unrar x file.rar
输出示例:
UNRAR 5.50 freeware Copyright (c) 1993-2016 Alexander Roshal Extracting from file.rar Creating etc OK Extracting etc/adduser.conf OK Extracting etc/apg.conf OK Extracting etc/appstream.conf OK Extracting etc/brltty.conf OK Extracting etc/ca-certificates.conf OK Extracting etc/sensors3.conf OK Extracting etc/sysctl.conf OK All OK
要测试档案的完整性,请输入以下命令:
$ unrar t file.rar
输出示例:
UNRAR 5.50 freeware Copyright (c) 1993-2016 Alexander Roshal Testing archive file.rar Testing etc/adduser.conf OK Testing etc/apg.conf OK Testing etc/appstream.conf OK Testing etc/brltty.conf OK Testing etc/ca-certificates.conf OK Testing etc/sensors3.conf OK Testing etc/sysctl.conf OK All OK
获取有关Unrar命令的帮助
执行以下命令:
$ man unar
或者
$ unrar | more
输出示例:
unrar UNRAR 5.50 freeware Copyright (c) 1993-2016 Alexander Roshal Usage: unrar <command> -<switch 1> -<switch N> <archive> <files...> <@listfiles...> <path_to_extract\> <Commands> e Extract files without archived paths l[t - ,b] List archive contents [technical[all], bare] p Print file to stdout t Test archive files v[t - ,b] Verbosely list archive contents [technical[all],bare] x Extract files with full path <Switches> - Stop switches scanning @[+] Disable [enable] file lists ad Append archive name to destination path ag[format] Generate archive name using the current date ai Ignore file attributes ap<path> Set path inside archive c- Disable comments show cfg- Disable read configuration cl Convert names to lower case cu Convert names to upper case dh Open shared files ep Exclude paths from names ep3 Expand paths to full including the drive letter f Freshen files id[c,d,p,q] Disable messages ierr Send all messages to stderr inul Disable all messages kb Keep broken extracted files n<file> Additionally filter included files n@ Read additional filter masks from stdin n<@list> Read additional filter masks from list file o[+|-] Set the overwrite mode ol - Process symbolic links as the link [absolute paths] or Rename files automatically ow Save or restore file owner and group p[password] Set password p- Do not query password r Recurse subdirectories sc<chr>[obj] Specify the character set sl<size> Process files with size less than specified sm<size> Process files with size more than specified ta<date> Process files modified after <date> in YYYYMMDDHHMMSS format tb<date> Process files modified before <date> in YYYYMMDDHHMMSS format tn<time> Process files newer than <time> to<time> Process files older than <time> ts[m|c|a] Save or restore file time (modification, creation, access) u Update files v List all volumes ver[n] File version control vp Pause before each volume x<file> Exclude specified file x@ Read file names to exclude from stdin x<@list> Exclude files listed in specified list file y Assume Yes on all queries