tar zip 打包、压缩与解压缩到指定目录的方法

本文介绍Linux中tar和zip命令的使用方法,包括如何使用tar进行打包、压缩、解压缩到指定目录等操作,以及zip命令的基本用法与参数详解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Tar打包、压缩与解压缩到指定目录的方法

 

tar在linux上是常用的打包、压缩、加压缩工具,他的参数很多,折里仅仅列举常用的压缩与解压缩参数

 

参数:

-c :create 建立压缩档案的参数;

-x : 解压缩压缩档案的参数;

-z : 是否需要用gzip压缩;

-v: 压缩的过程中显示档案;

-f: 置顶文档名,在f后面立即接文件名,不能再加参数

 

举例: 一,将整个/home/www/images 目录下的文件全部打包为 /home/www/images.tar

[root@xoaocom ~]# tar -cvf /home/www/images.tar /home/www/images ← 仅打包,不压缩

[root@xoaocom ~]# tar -zcvf /home/www/images.tar.gz /home/www/images ← 打包后,以gzip压缩

 

在参数f后面的压缩文件名是自己取的,习惯上用tar来做,如果加z参数,则以tar.gz 或tgz来代表gzip压缩过的tar file文件

 

举例: 二,将 /home/www/images.tar.gz 解压到/home/www下面

[root@xoaocom ~]# cd /home/www

[root@xoaocom ~]# tar -zxvf /home/images.tar.gz

 

解压到指定的目录

[root@xoaocom ~]# tar -zxvf /home/images.tar.gz -C /specific dir

 

解包到指定的目录

tar xvf filename.tar -C /specific dir

 

 

 

 

 

linux  zip命令的基本用法是:

zip [参数] [打包后的文件名] [打包的目录路径]

  linux  zip命令参数列表:

      -a     将文件转成ASCII模式
      -F     尝试修复损坏的压缩文件    
      -h     显示帮助界面
      -m     将文件压缩之后,删除源文件

      -n 特定字符串    不压缩具有特定字尾字符串的文件
      -o     将压缩文件内的所有文件的最新变动时间设为压缩时候的时间
      -q     安静模式,在压缩的时候不显示指令的执行过程
      -r     将指定的目录下的所有子目录以及文件一起处理
      -S     包含系统文件和隐含文件(S是大写)
      -t 日期     把压缩文件的最后修改日期设为指定的日期,日期格式为mmddyyyy

举例:

将/home/Blinux/html/ 这个目录下所有文件和文件夹打包为当前目录下的html.zip

zip –q –r   html.zip /home/Blinux/html

上面的命令操作是将绝对地址的文件及文件夹进行压缩.以下给出压缩相对路径目录

比如目前在Bliux这个目录下,执行以下操作可以达到以上同样的效果.

zip –q –r html.zip html

比如现在我的html目录下,我操作的zip压缩命令是

zip –q –r html.zip *

以上是在安静模式下进行的,而且包含系统文件和隐含文件

以下是我在SSH下的帮助,供大家参考:

Copyright (C) 1990-2005 Info-ZIP
Type 'zip "-L"' for software license.
Zip 2.31 (March 8th 2005). Usage:
zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list]
  The default action is to add or replace zipfile entries from list, which
  can include the special name - to compress standard input.
  If zipfile and list are omitted, zip compresses stdin to stdout.
  -f   freshen: only changed files  -u   update: only changed or new files
  -d   delete entries in zipfile    -m   move into zipfile (delete files)
  -r   recurse into directories     -j   junk (don't record) directory names
  -0   store only                   -l   convert LF to CR LF (-ll CR LF to LF)
  -1   compress faster              -9   compress better
  -q   quiet operation              -v   verbose operation/print version info
  -c   add one-line comments        -z   add zipfile comment
  -@   read names from stdin        -o   make zipfile as old as latest entry
  -x   exclude the following names  -i   include only the following names
  -F   fix zipfile (-FF try harder) -D   do not add directory entries
  -A   adjust self-extracting exe   -J   junk zipfile prefix (unzipsfx)
  -T   test zipfile integrity       -X   eXclude eXtra file attributes
  -y   store symbolic links as the link instead of the referenced file
  -R   PKZIP recursion (see manual)
  -e   encrypt                      -n   don't compress these suffixes

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值