admin 管理员组

文章数量: 1087582

tar打包与压缩

Linux压缩,解压缩常用命令

不能对目录进行压缩
压缩

  • gzip 文件
  • bzip2 文件
  • xz 文件

解压缩

  • gzip -d 压缩文件
  • bzip2 -d 压缩文件
  • xz -d 压缩文件

查看压缩文件内容(不解压情况下)

  • zcat 压缩文件
  • bzcat 压缩文件
  • xzcat 压缩文件

tar打包命令

命令格式:

  • tar 选项 打包后名字 被打包名字

选项:

  • c 创建打包文件
  • -f 指定打包后的文件名称(这个放在选项后面)
  • -z 调用gzip压缩工具,-J 调用xz压缩工具, -j 调用bzip2压缩工具
  • t 不解压缩,同时列出打包内容
  • x 解压缩
  • C 指定的解压路径
  • v 显示详细信息
[root@student opt]# tar -czf services.tar.gz services
[root@student opt]# ll
total 796
-rw-r--r--. 2 root root     68 Oct 10 20:00 a.txt
-rw-r--r--. 1 root root 670293 Oct 14 00:31 services
-rw-r--r--. 1 root root 136200 Oct 15 02:30 services.tar.gz
drwxr-xr-x. 2 root root      6 Oct 14 01:00 test
[root@student opt]# rm -rf /opt/services.tar.gz
[root@student opt]# ls
a.txt  services  test
[root@student opt]# tar -cJtf services.tar.xz services
tar: You may not specify more than one `-Acdtrux' or `--test-label' option
Try `tar --help' or `tar --usage' for more information.
[root@student opt]# tar -ctf services.tar.xz services
tar: You may not specify more than one `-Acdtrux' or `--test-label' option
Try `tar --help' or `tar --usage' for more information.
[root@student opt]# tar -cJf services.tar.xz services
[root@student opt]# ls
a.txt  services  services.tar.xz  test
[root@student opt]# tar -tf services.tar.xz
services
[root@student opt]# ll
total 760
-rw-r--r--. 2 root root     68 Oct 10 20:00 a.txt
-rw-r--r--. 1 root root 670293 Oct 14 00:31 services
-rw-r--r--. 1 root root 100752 Oct 15 02:32 services.tar.xz
drwxr-xr-x. 2 root root      6 Oct 14 01:00 test
[root@student opt]# tar -xf services.tar.xz -C /root/

本文标签: tar打包与压缩