3

tar命令详解---归档及压缩

 2 years ago
source link: https://blog.51cto.com/u_11806823/5526669
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

tar命令详解---归档及压缩

原创

爱草坪 2022-07-29 15:57:05 博主文章分类:linux系统管理 ©著作权

文章标签 压缩包 归档文件 tar linux 文章分类 Linux 系统/运维 阅读数210

作用:1.减小占用空间大小  2.整合分散的数据

•     归档的含义

        将许多零散的文件整理为一个文件

        文件总的大小基本不变

•     压缩的含义

        按某种算法减小文件所占用空间的大小

        恢复时按对应的逆向算法解压

•     常见的压缩格式及命令工具:

.gz    gzip

.bz2   bzip2

.xz    xz

•     tar 集成备份工具

–   -c:创建归档

–   -x:释放归档

–   -f:指定归档文件名称,必须在所有选项的最后

–   -z、-j、-J:调用 .gz、.bz2、.xz 格式工具进行处理

–   -t:显示归档中的文件清单

–   -C:指定释放路径

 tar 制作压缩包(tar打包)

格式:tar  选项   /路径/压缩包名字   /源数据…….

]# tar -zcf /root/xixi.tar.gz  /etc/passwd  /home

]# ls /root/

]# tar -jcf /root/haha.tar.bz2 /etc/passwd  /home

]# ls  /root/

]# tar -Jcf /root/hehe.tar.xz  /etc/passwd  /home/

]# ls /root/   

tar 释放压缩包(tar解包)

tar 选项  /路径/压缩包名字  选项  /释放的位置

–   -x:释放归档

–   -f:指定归档文件名称,必须在所有选项的最后

–   -C:指定释放路径    

]# mkdir /nsd01    

]# tar -xf  /root/haha.tar.bz2  -C  /nsd01

]# ls  /nsd01

]# ls  /nsd01/etc

]# ls  /nsd01/home

案例1:创建一个备份包

使用 tar 工具完成以下备份任务:

–   创建一个名为 /root/backup.tar.bz2 的归档文件

–   其中包含 /usr/local 目录中的内容

–   tar 归档必须使用 bzip2 进行压缩  

]# tar -jcf /root/backup.tar.bz2  /usr/local/

]# ls /root/

]# tar -tf /root/backup.tar.bz2   #查看tar包内容

  • 打赏
  • 1
  • 收藏
  • 评论
  • 分享
  • 举报

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK