GNU Tar provides the ability to create tar archives, as well as various other kinds of manipulation. For example, you can use Tar on previously created archives to extract files, to store additional files, or to update or list files which were already stored.

Initially, tar archives were used to store files conveniently on magnetic tape. The name "Tar" comes from this use; it stands for tape archiver. Despite the utility's name, Tar can direct its output to available devices, files, or other programs (using pipes), it can even access remote devices or files (as archives).[1]

常用选项

  • -c:创建一个新的归档文件。(取自于单词 Create)
  • -x:从归档文件中提取文件。(取自于单词 Extract)
  • -v:显示处理过程中的详细信息。(取自于单词 Verbose)
  • -f:指定归档文件的名称。(取自于单词 File)
  • -z:通过 gzip 压缩归档文件。

使用示例

# 解压当前目录下 mediawiki-1.43.0.tar.gz 中的所有文件
# 生成一个名为 mediawiki-1.43.0 的目录
tar -xvzf mediawiki-1.43.0.tar.gz
# 将 /var/www/wiki 整个文件夹压缩归档
# 并命名为 mediawiki-backup.tar.gz
tar -cvzf mediawiki-backup.tar.gz /var/www/wiki

如有内容修改建议,请联系天明

参考资料