Linux压缩打包命令使用思路方法

    tar命令
    [root@linux ~]# tar [-cxtzjvfpPN] 文件和目录 ....
    参数:
    -c :建立个压缩文件参数指令(create 意思);
    -x :解开个压缩文件参数指令!
    -t :查看 tarfile 里面文件!
    特别注意在参数下达中 c/x/t 仅能存在个!不可同时存在!
    不可能同时压缩和解压缩
    -z :是否同时具有 gzip 属性?亦即是否需要用 gzip 压缩?
    -j :是否同时具有 bzip2 属性?亦即是否需要用 bzip2 压缩?
    -v :压缩过程中显示文件!这个常用但不建议用在背景执行过程!
    -f :使用档名请留意在 f 的后要立即接档名喔!不要再加参数!
    例如使用『 tar -zcvfP tfile sfile』就是写法要写成
    『 tar -zcvPf tfile sfile』才对喔!
    -p :使用原文件原来属性(属性不会依据使用者而变)
    -P :可以使用绝对路径来压缩!
    -N :比后面接日期(yyyy/mm/dd)还要新才会被打包进新建文件中!
    --exclude FILE:在压缩过程中不要将 FILE 打包!
    范例:
    范例:将整个 /etc 目录下文件全部打包成为 /tmp/etc.tar
    [root@linux ~]# tar -cvf /tmp/etc.tar /etc
    gzip, zcat 命令
    [root@linux ~]# gzip [-cdt#] 档名
    [root@linux ~]# zcat 档名.gz
    参数:
    -c :将压缩资料输出到萤幕上可透过资料流重导向来处理;
    -d :解压缩参数;
    -t :可以用来检验个压缩档致性~看看文件有无
    -# :压缩等级-1 最快但是压缩比最差、-9 最慢但是压缩比最好!预设是 -6 ~
    范例:
    范例:将 /etc/man.config 复制到 /tmp 并且以 gzip 压缩
    [root@linux ~]# cd /tmp
    [root@linux tmp]# cp /etc/man.config .
    [root@linux tmp]# gzip man.config
    # 此时 man.config 会变成 man.config.gz !
    范例 2:将范例文件内容读出来!
    [root@linux tmp]# zcat man.config.gz
    # 此时萤幕上会显示 man.config.gz 解压缩的后文件内容!!
    范例 3:将范例文件解压缩
    [root@linux tmp]# gzip -d man.config.gz
    范例 4:将范例 3解开 man.config 用最佳压缩比压缩并保留原本文件
    [root@linux tmp]# gzip -9 -c man.config > man.config.gz
    bzip2, bzcat 命令
    [root@linux ~]# bzip2 [-cdz] 档名
    [root@linux ~]# bzcat 档名.bz2
    参数:
    -c :将压缩过程产生资料输出到萤幕上!
    -d :解压缩参数
    -z :压缩参数
    -# :和 gzip 同样都是在计算压缩比参数 -9 最佳 -1 最快!
    范例:
    范例:将刚刚 /tmp/man.config 以 bzip2 压缩
    [root@linux tmp]# bzip2 -z man.config
    # 此时 man.config 会变成 man.config.bz2 !
    范例 2:将范例文件内容读出来!
    [root@linux tmp]# bzcat man.config.bz2
    # 此时萤幕上会显示 man.config.bz2 解压缩的后文件内容!!
    范例 3:将范例文件解压缩
    [root@linux tmp]# bzip2 -d man.config.bz2
    范例 4:将范例 3解开 man.config 用最佳压缩比压缩并保留原本文件
    [root@linux tmp]# bzip2 -9 -c man.config > man.config.bz2
    compress 命令
    [root@linux ~]# compress [-dcr] 文件或目录
    参数:
    -d :用来解压缩参数
    -r :可以连同目录下文件也同时给予压缩呢!
    -c :将压缩资料输出成为 standard output (输出到萤幕)
    范例:
    范例:将 /etc/man.config 复制到 /tmp 并加以压缩
    [root@linux ~]# cd /tmp
    [root@linux tmp]# cp /etc/man.config .
    [root@linux tmp]# compress man.config
    [root@linux tmp]# ls -l
    -rw-r--r-- 1 root root 2605 Jul 27 11:43 man.config.Z
    范例 2:将刚刚压缩档解开
    [root@linux tmp]# compress -d man.config.Z
    范例 3:将 man.config 压缩成另外个文件来备份
    [root@linux tmp]# compress -c man.config > man.config.back.Z
    [root@linux tmp]# ll man.config*
    -rw-r--r-- 1 root root 4506 Jul 27 11:43 man.config
    -rw-r--r-- 1 root root 2605 Jul 27 11:46 man.config.back.Z
    #
Tags: 

延伸阅读

最新评论

发表评论