tar命令tar命令详解




tar命令tar命令详解

2022-07-20 20:34:15 网络知识 官方管理员

怎样使用tar命令打包(备份)文件?

A:Thesyntaxoftaris:

tar[options][files]

Theoptionsusedmostoftenwithtarareasfollows:

cCreatesanewbackup,overwritinganyfilesalreadyonthebackupdestination.

xExtractsfilesfrombackupmedia.

tListsthecontentsofbackupmedia.

vDisplaysthenameofeachfilebeingprocessed.

fCreatesbackupsonaspecifieddevice.

uAddsfilestothebackupiftheyarenotalreadythere,oriftheyhavebeenmodifiedsincetheywerelastwrittenonthebackup.

步骤:

1)估算打包文件的大小,确定使用档案媒体(archivemedia)的空间,用命令du-s

例如:

$lf

a.out*fork.cmboxtime.c

atoi.cint.cmemcpy.cvi

$du-s

296.

$

该例显示的296代表thetotalnumberof512-byteblocks,计算:512*296/1024=148kilobytes.

2)制作备份,用命令tarcvf/dev/fd0135ds18.(将该目录下的所有内容备份到1.44英寸软盘中whereccausesanewbackuptobecreated,vcauseseachfiletobedisplayedasthebackinguptakesplace,andfcausesthesubsequentargument--/dev/fd0135ds18tobethedestinationofthebackup.)

注:平时硬盘上的备份,我们一般用命令tarcvffilename.tar.

例如:

$tarcvfwuyd.tar.

a./.profile2tapeblocks

a./.lastlogin0tapeblocks

a./mbox10tapeblocks

a./fork.c2tapeblocks

a./memcpy.c1tapeblocks

a./.sh_history3tapeblocks

a./a.out91tapeblocks

a./time.c1tapeblocks

a./vi169tapeblocks

a./int.c1tapeblocks

a./atoi.c1tapeblocks

tar:sameasarchivefile:./wuyd.tar

a./.scoadmin.pref1tapeblocks

$lf

a.out*fork.cmboxtime.cwuyd.tar

atoi.cint.cmemcpy.cvi

我们还可以用命令tarcvf/dev/fd0135ds18./filename将该目录下的名为filename的文件备份到archivemedia中

怎样列出tar文档的内容?

A:tartvf/dev/fd0135ds18

tartvffilename.tar

例如:

$tartvfwuyd.tar

tar:blocksize=20

rw-------203/50896Sep1715:072003./.profile

r--------203/210Sep2419:492003./.lastlogin

rw-------203/504720Sep2111:172003./mbox

rw-r--r--203/50583Sep1715:272003./fork.c

rw-r--r--203/50218Sep1720:222003./memcpy.c

rw-------203/501474Sep2420:262003./.sh_history

rwxr-xr-x203/5046224Sep2221:002003./a.out

rw-r--r--203/50341Sep1909:022003./time.c

rw-r--r--203/5086283Sep2109:142003./vi

rw-r--r--203/5093Sep2110:532003./int.c

rw-r--r--203/50144Sep2221:002003./atoi.c

rw-r--r--0/341Sep2320:342003./.scoadmin.pref

$

怎样从tar文档中导出文件?

A:tarxvf/dev/fd0135ds18

tarxvffilename.tar

例如:

$mkdiruu;cpwuyd.tar./uu

$lf

a.out*fork.cmboxtime.cvi

atoi.cint.cmemcpy.cuu/wuyd.tar

$cduu

$tarxvfwuyd.tar

tar:blocksize=20

x./.profile,896bytes,2tapeblocks

x./.lastlogin,0bytes,0tapeblocks

x./mbox,4720bytes,10tapeblocks

x./fork.c,583bytes,2tapeblocks

x./memcpy.c,218bytes,1tapeblocks

x./.sh_history,1474bytes,3tapeblocks

x./a.out,46224bytes,91tapeblocks

x./time.c,341bytes,1tapeblocks

x./vi,86283bytes,169tapeblocks

x./int.c,93bytes,1tapeblocks

x./atoi.c,144bytes,1tapeblocks

x./.scoadmin.pref,41bytes,1tapeblocks

$

我们可用命令tarxvf/dev/fd0135ds18./filename导出archivemedia中的单个文件

例如:

$lf

wuyd.tar

$tarxvfwuyd.tar./time.c

tar:blocksize=20

x./time.c,341bytes,1tapeblocks

$lf

time.cwuyd.tar

$

怎样使用tar命令提供的简写形式?

A:

$more/etc/default/tar

#@(#)def135.src25.294/07/25

#

#Copyright(C)1987-1994TheSantaCruzOperation,Inc.

#AllRightsReserved.

#Theinformationinthisfileisprovidedfortheexclusiveuseof

#thelicenseesofTheSantaCruzOperation,Inc.Suchusershavethe

#righttouse,modify,andincorporatethiscodeintootherproducts

#forpurposesauthorizedbythelicenseagreementprovidedtheyinclude

#thisnoticeandtheassociatedcopyrightnoticewithanysuchproduct.

#Theinformationinthisfileisprovided"ASIS"withoutwarranty.

#

#default/tar-archivedevices:tar(C)

#

#deviceblocksizetape

#

archive0=/dev/rfd048ds918360n

archive1=/dev/rfd148ds918360n

archive2=/dev/rfd096ds15101200n

archive3=/dev/rfd196ds15101200n

#archive4=/dev/rfd096ds918720n

archive4=/dev/rfd0135ds918720n

archive5=/dev/rfd1135ds918720n

#archive5=/dev/rfd196ds918720n

archive6=/dev/rfd0135ds18181440n

archive7=/dev/rfd1135ds18181440n

archive8=/dev/rct0200y

archive9=/dev/rctmini200y

archive10=/dev/rdsk/fp03d18720n

archive11=/dev/rdsk/fp03h181440n

archive12=/dev/rdsk/fp03v211020330n

#

#Thedefaultdeviceintheabsenceofanumericor"-fdevice"argument

archive=/dev/rfd0135ds18181440n

$

从上面可以看出4代表/dev/rfd0135ds9设备,而默认的设备是/dev/rfd0135ds18,所以tarxvf/dev/rfd0135ds9./filename可以简写为tarxv4./filename,而tarcvf/dev/fd0135ds18.可以简写为tarcv.


发表评论:

最近发表
网站分类
标签列表