linux 打包文件

    xiaoxiao2022-07-14  151

    打包文件概述

    多个文件或者一个目录打包成一个大文件,linux中的打包命令叫做tartar命令就是将多个文件前后链接一起形成一个大文件tar命令并不对文件进行压缩

    tar命令如下

    【1】tar -cf [ 打包文件名 ][ 要打包的文件 / 列表 ]

    [ylp@localhost tmp]$ tar -cf file.tar file01 file02 file03 [ylp@localhost tmp]$ tar -cf file1.tar file04

    【2】tar -tf [打包文件名],查看打包文件中所有文件名

    [ylp@localhost tmp]$ tar -tf file.tar /tmp/file01 /tmp/fiel02 /tmp/file03

    【3】--delete删除打包文件中的某个特定文件

    [ylp@localhost tmp]$ tar -f file.tar --delete file01 [ylp@localhost tmp]$ tar -tf file.tar /tmp/file03 /tmp/file02

    【4】-A 选项合并两个打包文件

    [ylp@localhost tmp]$ tar -f file.tar -A file01.tar [ylp@localhost tmp]$ tar -tf file.tar /tmp/file02 /tmp/file03 /tmp/file04

    【5】-r选项 向打包文件中添加新文件

    [ylp@localhost tmp]$ tar -f file.tar -r ~/fileA.txt

    【6】tar -xf [ 要解包的文件名 ]

    [ylp@localhost tmp]$ tar -xf file.tar -C /sampledir01

     

    压缩文件

    【1】压缩文件 gzip [ 要压缩的文件名 ] ,压缩后的文件自动替换源文件,自动添加.gz后缀

    [ylp@localhost tmp]$ gzip file.tar

    【2】解压文件 gzip -d [ 要解压的文件名 ]   解压后的文件替换了压缩文件

    [ylp@localhost tmp]$ gzip -d file.tar.gz

     

    gzip只能够单个的压缩文件,而不能将多个文件或者整个目录压缩到一个文件中,因此gzip往往要和tar命令一起连用,可以用tar先打包,然后用gzip压缩,反过来就要用gzip先解压,然后再用tar再解包。

    tar -czf 【打包压缩生成的文件名,后缀.tar.gz】【文件列表】   将一批文件打包压缩

    [ylp@localhost tmp]$ tar -czf sameple.tar.gz file01 file02 file03

    tar -xzf 【要解压缩解包的文件名,后缀.tar.gz】

    [ylp@localhost tmp]$ tar -xzf sameple.tar.gz

     

     

    最新回复(0)