tar
命令详解
tar
(Tape Archive)是 Unix 和 Linux 系统中一个非常强大的文件归档工具,用于创建、提取和管理归档文件。归档文件可以包含一个或多个文件和目录,常用于备份、存档和传输数据。tar
支持多种压缩方式,如 gzip
、bzip2
和 xz
。
基本语法
tar [选项] [归档文件] [文件或目录...]
常用选项
-
-c
或--create
:- 创建新的归档文件。
tar -cvf archive.tar file1 file2
-
-x
或--extract
或--get
:- 从归档文件中提取文件。
tar -xvf archive.tar
-
-t
或--list
:- 列出归档文件中的内容。
tar -tvf archive.tar
-
-f
或--file=ARCHIVE
:- 指定归档文件的名称。
tar -cvf archive.tar file1 file2
-
-v
或--verbose
:- 显示详细信息,如处理的文件名。
tar -cvf archive.tar file1 file2
-
-z
或--gzip
或--gunzip