Rar is a very popular compression format used for different purposes. A lot of files like documents, image files, source code, etc. are compressed using rar compression format. In this tutorial, we will look at how to install rar tool for Ubuntu, Debian, Kali, and Mint and then list and extract files and directories.
Rar是一种非常流行的压缩格式,用于不同目的。 许多文件(如文档,图像文件,源代码等)都使用rar压缩格式进行压缩。 在本教程中,我们将研究如何为Ubuntu,Debian,Kali和Mint安装rar工具,然后列出并提取文件和目录。
安装Unrar (Install Unrar)
We will use apt
package manager in order to install unrar
package.
我们将使用apt
软件包管理器来安装unrar
软件包。
$ apt install unrar
列出Rar文件内容 (List Rar File Contents)
We can list contents of a rar files with l
option and the rar file name. In this example we will list contents of rar file named ans.rar
.
我们可以使用l
选项和rar文件名列出rar文件的内容。 在此示例中,我们将列出名为ans.rar
的rar文件的内容。
$ unrar l ans.rar
The list operation will print attributes, size, date time and names.
列表操作将打印属性,大小,日期时间和名称。
卸载所有文件和目录 (Unrar All Files and Directories)
We can use e
option in order to extract all files and directories inside a rar file. In this example, we will extract contents of ans.rar
. -r
is used to extract recursively which means all sub files and directories will be extracted too.
我们可以使用e
选项来提取rar文件中的所有文件和目录。 在此示例中,我们将提取ans.rar
内容。 -r
用于递归提取,这意味着所有子文件和目录也将被提取。
$ unrar e -r ans.rar
Unrar单个文件或目录(Unrar Single File or Directory)
Some times we may need to extract only a single file or directory from a rar file. This may be a backup rar
file where we only need a single file or directory. We need to specify the file and directory path and name in a relative manner. In this example, we will extract a file named data.txt
有时我们可能只需要从rar文件中提取单个文件或目录。 这可能是一个备份rar
文件,我们只需要一个文件或目录。 我们需要以相对方式指定文件和目录的路径和名称。 在此示例中,我们将提取一个名为data.txt
的文件
$ unrar e ans.rar data.txt
Or if the file is locate in the back/files
directory we can use following command.
或者,如果文件位于back/files
目录中,则可以使用以下命令。
$ unrar e ans.rar back/files/data.txt
保留目录结构 (Preserve Directory Structure)
While taking backups with rar command the absolute directory path can be stored into the rar file. This is useful for the recovery process where we do not need to specify the extract path explicitly. We can use x
option in order to preserve the directory structure while extracting. We will use -r
as a recursive extract.
使用rar命令进行备份时,绝对目录路径可以存储到rar文件中。 这对于无需显式指定提取路径的恢复过程很有用。 我们可以使用x
选项以便在提取时保留目录结构。 我们将使用-r
作为递归提取。
$ unrar x -r ans.rar
翻译自: https://www.poftut.com/list-unrar-rar-files-ubuntu-debian-kali-mint/