touch file1 touch file2 mkdir dir1 touch dir1/file3 # 普通tar文档 tar -cf tar-file.tar file1 file2 dir1 # 压缩的tar文档(使用gnuzip算法) tar -czf tgz-file.tgz file1 file2 dir1
** tgz格式一般也写做tar.gz **算法
# 对于压缩的tar文档,也使用相同的命令 mint@lenovo ~/temp $ tar -tf tar-file.tar file1 file2 dir1/ dir1/file3/ mint@lenovo ~/temp $ tar -tf tgz-file.tgz file1 file2 dir1/ dir1/file3
# 未压缩 tar -xf tar-file.tar # 使用gnuzip算法进行压缩的tar文档 tar -xzf tgz-file.tar
# 未进行压缩的tar文档 tar -xf tar-file.tar -C /path/to/destination # 使用gunzip算法压缩的tar文档 tar -xzf tgz-file.tgz -C /path/to/destination
mint@lenovo ~/temp $ mkdir ex mint@lenovo ~/temp $ tar -xf tar-file.tar -C ex/ mint@lenovo ~/temp $ cd ex/ mint@lenovo ~/temp/ex $ ls dir1 file1 file2