您的位置首页百科问答

tar命令使用简介

tar命令使用简介

的有关信息介绍如下:

tar命令使用简介

简单介绍linux tar命令的使用,tar是linux下的一款打包软件,类似windos的打包压缩软件。介绍文件打包命令tar,可将多个文件打成一个包,方便传输。常用的几个参数,类似增删改查。

创建

-f, --file=ARCHIVE use archive file or device ARCHIVE :使用存档文件或设备档案(后面跟所要打包或解包的包名)

-v, --verbose verbosely list files processed:详细显示

-c, --create create a new archive : 建立新的归档文件

tar cvf applepen.tar apple pen

把apple pen这两个文件打包成一个文件applepen.tar,.tar是文件后缀。

记住-f后面先写打包的包名 applepen,后面是要打包的内容,apple和pen。

压缩

-z, --gzip ilter the archive through gzip:使用gzip压缩

可以调用gzip,bzip等压缩工具,对包进行压缩。gzip最常用,使用gzip即可,.gz为后缀。

解包

-x, --extract, --get extract files from an archive:解压(自动识别各种格式的压缩)

-C, --directory=DIR change to directory DIR:加压到指定目录

tar xvf app/applepen.tar

-f后面跟所要加压的包即可

查看

-t, --list list the contents of an archive: 查看存档的内容列表

tar tvf applepen.tar

-t查看包里的内容,并不解压。

追加

-r, --append append files to the end of an archive:附加文件

tar rvf applepen.tar a1 a2

把a1、a2追加到已经打好的包里

删除

--delete delete from the archive (not on mag tapes!):删除包里的文件

tar --delete -vf applepen.tar a1 a2 a3

删除包里面的文件a1、a2、a3,没有的话会报错,注意名子要一样。

注意

不要用绝对路径,使用相对路径;

tar: Removing leading `/' from member names (移除绝对路径的/)

如果带/,解压后可能覆盖原有文件。

不要在当前目录打包,在上级目录打包

tar: ./aaa.tar.gz: file is the archive; not dumped

当前目录会报这个错