zoukankan      html  css  js  c++  java
  • 十二 Linux之tar解压缩

      tar是常用的解压缩指令,常用参数

    • -c 创建一个压缩包
    • v 显示压缩的详细信息
    • -z 压缩,如果没有只是打包
    • -f 压缩后的目标文件名
    • -x解压
    • -C解压到指定目录下

    实例

    1. 把所有名为cc*.txt的文件打包到file.tar下
      [root@centoscc cc]# tar -cf file.tar cc*.txt
      [root@centoscc cc]# ls -l
      总用量 60
      ...
      -rw-r--r--. 1 root root  10240 12月 24 19:11 file.tar
      ...
    2. 把文件root1.txt增加到file.tar文件中
      [root@centoscc cc]# tar -rf file.tar root1.txt
    3. 更新file.tar包中的root1.txt文件
      [root@centoscc cc]# tar -uf file.tar root1.txt
    4. 列出包中的文件
      [root@centoscc cc]# tar -tf file.tar
      cc4.txt
      cc.txt
      root1.txt
    5. 解出包中内容到同一目录下
      [root@centoscc cc1]# ls -l
      总用量 12
      drwx--x--x. 3 root root    18 12月 20 16:25 cc1
      drwxr-xr-x. 2 root root     6 12月 20 16:24 cc11
      -rw-r--r--. 1 root root 10240 12月 24 19:11 file.tar
      [root@centoscc cc1]# tar -xf file.tar
      [root@centoscc cc1]# ls -l
      总用量 24
      drwx--x--x. 3 root root    18 12月 20 16:25 cc1
      drwxr-xr-x. 2 root root     6 12月 20 16:24 cc11
      -rw-r--r--. 1 root root    16 12月 20 21:19 cc4.txt
      -rw-r--r--. 1 root root    15 12月 20 21:21 cc.txt
      -rw-r--r--. 1 root root 10240 12月 24 19:11 file.tar
      -rw-r--r--. 1 root root    16 12月 22 20:37 root1.txt
    6. 解出包中内容到指定目录下(该目录要先创建,否则会报错)
      [root@centoscc cc1]# tar -xvf file.tar -C file1
      cc4.txt
      cc.txt
      root1.txt
      [root@centoscc cc1]# cd file1
      [root@centoscc file1]# ls -l
      总用量 12
      -rw-r--r--. 1 root root 16 12月 20 21:19 cc4.txt
      -rw-r--r--. 1 root root 15 12月 20 21:21 cc.txt
      -rw-r--r--. 1 root root 16 12月 22 20:37 root1.txt

    tar调用其他压缩程序

    常用指令:

    • z:把tar包压缩成.tar.gz格式:

      # tar -czf file1.tar.gz cc*.txt   解压:# tar -xzf file1.tar.gz 

    • Z:把tar包压缩成.tar.Z
    • j:把tar包压缩成 .tar.bz2
  • 相关阅读:
    最实用的logback讲解(2)—appender
    深入理解lombok
    idea(三)最值得安装的几款插件
    idea(二)初次安装强烈建议修改的配置
    swagger2的使用和swagger2markup离线文档的生成(最简单的方式)
    maven(一) 基础知识
    maven(二)pom文件详解
    ubuntu下jdk的安装
    maven(三)最详细的profile的使用
    profile之springboot
  • 原文地址:https://www.cnblogs.com/Cc905/p/14185962.html
Copyright © 2011-2022 走看看