tar 命令使用总结

Update: 2019-5-14

manipulate tape archives.

tar creates and manipulates streaming archive files.

This implementation can extract from tar, pax, cpio, zip, jar, ar, and ISO 9660 cdrom images

and can create tar, pax, cpio, ar, and shar archives.

用来压缩和解压文件。tar 本身不具有压缩功能, 它是调用压缩功能实现的。

常用参数

模式说明符( tar 命令后的第一个参数必须是下面中的某一个)

-c 压缩文件

-x 解压文件

-t 查看文件压缩内容

-r 向压缩归档文件末尾追加文件

可选参数

-v 显示操作过程所有信息

-C 切换到指定目录

-f 指定压缩文件

常见用法

新建 a.txtb.txt 文件。

  1. a.txtb.txt 文件打包成 new.tar 文件.
tar -cf new.tar a.txt b.txt
  1. 列举出 new.tar 文件压缩内容
chenxi$ tar -tvf new.tar 
-rw-r--r--  0 chenxi staff       5  5 14 22:46 a.txt
-rw-r--r--  0 chenxi staff       6  5 14 22:46 b.txt
  1. 解压 new.tardir 目录下

新建 dir 目录, 执行命令

chenxi$ tar -xvf new.tar -C dir
x a.txt
x b.txt