文逸首页 小文论坛 文逸博客 精华文章
 首页 | 新闻 | 论坛 | 博客 | 专题 | FTP | 金融 | 微博 | 图库 | MyHome | 搜索 | 登陆 | 注册 | 帮助 | 设为首页  ·在线人数: 1754
 §您的位置:文逸首页 > chinesedragon 's home > 【教育学习】专栏 > Linux操作.
chinesedragon 的主页网址:http://wonyen.net/home.aspx?id=chinesedragon 给我留言

 § chinesedragon  的【教育学习】专栏

  作者:chinesedragon  发表时间: 2005/12/15 23:54:16    查看: 10263     评论: 9
标题: Linux操作系统打包命令使用技巧

Linux操作系统打包命令使用技巧 
  发表日期:2005年7月24日             

--------------------------------------------------------------------------------
 
 


  本人在Unix系统业务使用(特别是数据管理与备份)中,经过一番研究、整理后,充分利用Unix系统本身的命令tar、cpio和compress等来做到打包和压缩,使之充当类似DOS下的压缩软件,同时在Unix系统中亦具有通用性。

  在Unix系统中,是先通过cpio或tar将众多的文件打包成一个文件库后,再用compress将文件库压缩来达到目的的。下面分别以cpio和tar来说明使用的方法和步骤。

  一、cpio

  1.文件或目录打包。

  打包有如下多种情况:

  A)含子目录打包:

  find /usr/lib -print|cpio -o〉/u0/temp1.cpio

  将/usr /lib目录下的文件与子目录打包成一个文件库为/u0/temp1.cpio。

  若通过-o选项来打包整个目录下的所有文件与子目录,常先利用find目录名-print来找出所有文件与子目录的名称,通过管道“|”传给cpio打包。

  B)不含子目录的打包:

  ls /usr/lib|cpio -o〉/u0/temp1.cpio

  将/usr/lib目录下的文件(不含子目录下的文件)打包成一个文件库为/u0/temp1.cpio。

  C)特定文件打包:

  可利用文本搜索命令grep与管道配合,可以排除或选择特定类型的文件传给cpio打包。如:ls /usr/lib/*.c|cpio -o〉/u0/temp1.cpio

  或ls /usr/lib|grep ′.c$′|cpio -o〉/u0/temp1.cpio

  意思均为找出/usr/lib目录下以.c结尾的文件予以打包。

  又如:ls /usr/lib|grep abcd|cpio -o〉/u0/temp1.cpio ,其意为找出/usr/lib目录下文件名中含有abcd字符的文件予以打包。

  ls /usr/lib|grep -v abcd|cpio -o〉/u0/temp1.cpio,其意为找出/usr/lib目录下文件名中不含 abcd 字符的文件予以打包。-v选项在grep命令中的意思是排除含有字符串的行列。

  如此,可充分利用Unix的管道和一些命令的强大功能来实现文件的打包。

  2.压缩:

  文件打包完成后,即可用Unix中的compress命令(/usr/bin下)压缩打包文件。对一般的文本文件,压缩率较高,可达81%。

  compress /u0/temp1.cpio则将文件库/u0/temp1.cpio压缩为/u0/temp1.cpio.Z(自动添加.Z并删除/u0/temp1.cpio )。

  3.解压:

  uncompress /u0/temp1.cpio.Z则自动还原为/u0/temp1.cpio。

  4.解包展开:

  将按原目录结构解包展开到当前所在目录下。若以相对路径打包的,当解包展开时,也是以相对路径存放展开的文件数据;若以绝对路径打包的,当解包展开时,也是以绝对路径存放展开的文件数据。因此注意若为相对路径,应先进入相应的目录下再展开。

  cd /u1

  cpio -id〈/u0/tmp1.cpio则将/u0/temp1.cpio解压到/u1下(这里假设temp1.cpio以相对路径压缩)。

  若加u选项,如cpio -iud〈/u0/temp1.cpio则文件若存在将被覆盖,即强制覆盖。

  cpio -id〈/u0/temp1.cpio *.c 则展开其中的*.c文件,类似于DOS系统中的Pkzip软件中Pkunzip -d temp1.zip解包功能。

  5.显示:

  cpio -it〈/u0/temp1.cpio [*.c] 显示文件库内的文件名称,类似于DOS系统中的Pkzip软件中Pkunzip -vbnm temp1.zip功能。

  二、tar

  1.文件或目录打包:

  tar -cvf /u0/temp2.tar /usr/lib

  将/usr/lib目录下的文件与子目录打包成一个文件库为/u0/temp2.tar。

  tar -cvf /u0/temp2.tar /usr/lib *.c *.f

  将/usr/lib目录下的*.c *.f等文件(不含子目录)打包。

  注意:如果指定文件如*.c *.f或*.*,则打包时均不含子目录。如果指定为.或*,则含子目录。

  2.压缩:

  同上:compress /u0/temp2.tar压缩为/u0/temp2.tar.Z

  3.解压:

  uncompress /u0/temp2.tar.Z则还原为/u0/temp2.tar。

  4.解包展开:

  tar -xvf /u0/temp2.tar

  若以相对路径打包的,解包时,以相对路径存放展开的文件数据;若以绝对路径打包的,解包时,以绝对路径存放展开的文件数据。

  若指定展开的文件名,须注意文件的目录路径。

  5.显示:

  tar -tvf /u0/temp2.tar 显示文件库内的文件名称。当指定文件名时,亦须注意文件的路径。

  相对来说这两个命令各有优缺点。

  1)tar速度比cpio慢,且不能跨越两份存储媒体,但文件格式几乎在所有的Unix系统中都能通用,且使用简便。

  2)cpio则由于可通过管道功能,使得其打包时的文件选择、排除功能非常强,且能跨越多份媒体,并能备份特殊的系统文件。

  另外,压缩命令compress比DOS下的Pkzip的压缩率要低些。经测试,在一个目录下527个文本文件共15.7MB,在Unix打包后用compress压缩,大小为 2.1MB;相同的文件拷到DOS系统用Pkzip压缩,则大小为1.4MB。
 
 
 

分享到:


 §评论: Linux操作系统打包命令使用技巧

  回复者:SKSK    回复时间:2010/1/9 14:32:44    [第1评]
Przision levels. high quality swiss Therefore, the cart is Mont Blanc Replica Watches fhrend is prerogative the swiss watches in stock use travail veil the Cartier Tortue Platinum and 18kt White Gold XL Mens Watch W1546151 watch current technology to go designer replica watches into their masterpieces. The high quality swiss company's chronicle contains many replica Longines Master Collection Mens Watch L2.648.4.78.5 unconventional facts, equivalent considering replica Omega Constellation My Choice Quartz Mini Ladies Watch 1561.61.00 the installation of the Louis Vuitton Tambour Chronographs Mens Tambour Automatic watch LV042 watch highest chronograph effect 1882, best swiss replicas also the brother services of U-Boat watches the Kirium TI5 at cheap Alain Silberstein Sport Krono A_SILB-5-11 watch replica the actualize of the cheap Timemaster Automatic C_SWISS-9-392 watch replica 20th Century, the leading watches replica chronograph to the 100th cheap U-Boat Flightdeck UB-3-961 watch replica of a sustain Manahme cheap IWC Big Pilots Spitfire IWC-42-490 watch replica knnte was launched dominion watches replica 1916 to life, followed best watches replica by the layout of watches replica an analog quartz chronograph watch replica force 1983, besides teeming more. Today, document Heuer model watches are affordable seeing cheap ugg UGG Womens Bailey Button sale Verfgung. These alluring specimens cheap ugg UGG Womens Bailey Button sale are a flag known cheap ugg UGG Womens Bailey Button sale fr przise movements and cheap ugg UGG Womens Bailey Button sale a superior sports actualize. cheap ugg sale Every document Heuer portrait cheap ugg UGG Womens Bailey Button sale project to grant superlative cheap Women's UGG sale standards of timekeeping. Wearing cheap ugg sale a tab Heuer Aquaracer cheap ugg sale Quartz Mens factor enjoying cheap Women's UGG sale the Qualitt one shot of the incomparable brands, which handbag like mirror replica is recognized worldwide.Click www.fashion-replica.com replica handbag further treasure trove the cheap Fendi handbags representative again tab Heuer cheap Marc Jacobs handbags exulting Watches now! Market designer handbag replica information by Rolex Rolex replica gucci handbag Submariner replica can be Louis vuitton handbag replica a real Rolex jewelry Chloe handbags on the market. As cheap replica handbag one of the most Louis Vuitton Wallet Pocket Organizer LVss--41 modern luxury in the world to see, the Rolex Rolex Oyster Perpetual Day-Date Mens Watch 118239-SD is also krzester speed. Maurice Lacroix Intuition Ladies Watch IN3012-PS103-120 However, different types of Omega Seamaster Aqua Terra Ladies Watch 2565.75.00 replica Rolex watches have Longines Hydro Conquest sale come into the market, watches replica people would rather fr watch replicas time to analyze and Ulysse Nardin Dual Time 42 mm Mens Watch 243-55-92 investigate all options and Seiko Chronograph Two-Tone Mens Watch SND583 sufficient information before deciding Raymond Weil Freelancer Mens Watch 2710-ST-20001 which one to buy. high replicas Some customers want to know why you select at the replica Rolex watches A Pink Ugg Boots 5825 Classic Short knockoffs major reason wre that discount UGG KnightsBridge Rolex replica watches are Chestnut KnightsBridge UGG Boots 5119 knockoffs of high quality and Classic tall boots very cheap compared to discount Ugg New Tall  Boots the original. Buying a [b][url=http://www.uggbootssaleo


  回复者:腾讯    回复时间:2011/11/20 18:16:02    [第2评]
QQ抽奖

QQ抽奖活动

腾讯周年挖宝行动是真的吗

腾讯公司有抽奖活动吗

QQ中奖是真的吗

腾讯中奖是真的吗


  回复者:王博    回复时间:2012/7/24 22:16:15    [第3评]
要求大家点击一下查看这些不法分子!
星光大道抽奖活动
星光大道官方网站
星光大道中奖查询网
星光光大道中奖是真的吗
QQ信封


3 条评论;  每页显示 15 条评论;   1 / 1               ↑到页首




您未登陆,发表评论时请填写:用户名  密码   注册新用户  
 评论: Linux操作系统打包命令使用技巧
内容 (8000字以内)
 (CTRL+ENTER提交) 
  关闭窗口  
用户登陆
我要发表文章
搜 索
§chinesedragon 的网志导航
感想随笔(4)
生活休闲(0)
饮食健康(0)
自然妙趣(1)
潮流时尚(0)
游览见闻(0)
情感绿洲(6)
娱乐搞笑(4)
读图时代(3)
影音视听(4)
商业新知(0)
理论研究(6)
时事纵横(13)
社会文化(15)
文学欣赏(3)
教育学习(15)
§chinesedragon 的友情链接
关于文逸 | 小文论坛 | 文逸博客 | 文逸金融 | 精华文章网站地图 | 联系我们 | 隐私保护
 Copyright© WWW.WONYEN.NET 2003 - 2021  闽ICP备09016518号-16   本站最高 10508 人同时在线,发生时间 2005-5-17 5:09:15 
 文逸科技 制作维护