In Unix, what is tar, and how do I use it?

 

In Unix, the name of the tar command is short for tape archiving, the storing of entire file systems onto magnetic tape, which is one use for the command. However, a more common use for tar is to simply combine a few files into a single file, for easy storage and distribution.

To combine multiple files and/or directories into a single file, use the following command:

  tar -cvf file.tar inputfile1 inputfile2

Replace inputfile1 and inputfile2 with the files and/or directories you want to combine. You can use any name in place of file.tar, though you should keep the .tar extension. If you don‘t use the f option, tar assumes you really do want to create a tape archive instead of joining up a number of files. The v option tells tar to be verbose, which reports all files as they are added.

To separate an archive created by tar into separate files, at the shell prompt, enter:

  tar -xvf file.tar

Compressing and uncompressing tar files

Many modern Unix systems, such as Linux, use GNU tar, a version of tar produced by the Free Software Foundation. If your system uses GNU tar, you can easily use gzip (the GNU file compression program) in conjunction with tar to create compressed archives. To do this, enter:

  tar -cvzf file.tar.gz inputfile1 inputfile2

Here, the z option tells tar to zip the archive as it is created. To unzip such a zipped tar file, enter:

  tar -xvzf file.tar.gz

Alternatively, if your system does not use GNU tar, but nonetheless does have gzip, you can still create a compressed tar file, via the following command:

  tar -cvf - inputfile1 inputfile2 | gzip > file.tar.gz

Note: If gzip isn‘t available on your system, use the Unix compress command instead. In the example above, replace gzip with compress and change the .gz extension to .Z (the compress command specifically looks for an uppercase Z). You can use other compression programs in this way as well. Just be sure to use the appropriate extension for the compressed file, so you can identify which program to use to decompress the file later.

If you are not using GNU tar, to separate a tar archive that was compressed by gzip, enter:

  gunzip -c file.tar.gz | tar -xvf -

Similarly, to separate a tar archive compressed with the Unix compress command, replace gunzip with uncompress.

Lastly, the extensions .tgz and .tar.gz are equivalent; they both signify a tar file zipped with gzip.

Additional information

Keep the following in mind when using the tar command:

  • The order of the options sometimes matters. Some versions of tar require that the f option be immediately followed by a space and the name of the .tar file being created or extracted.
  • Some versions require a single dash before the option string (e.g., -cvf).

GNU tar does not have either of these limitations.

The tar command has many additional command options available. For more information, consult the manual page. At the shell prompt, enter:

  man tar

GNU tar comes with additional documentation, including a tutorial, accessible through the GNU Info interface. You can access this documentation by entering:

  info tar

Within the Info interface, press ? (the question mark) for a list of commands.

At Indiana University, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?

This document was developed with support from National Science Foundation (NSF) grant OCI-1053575. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the NSF.

时间: 2024-10-12 17:02:49

In Unix, what is tar, and how do I use it?的相关文章

tar备份文件

tar命令 tar是一个已移植到Linux中的经典UNIX命令.tar是Tape ARchive(磁带归档)的缩写,最初设计用于将文件打包到磁带上.它是一个基于文件的命令,它本质上是连续地.首尾相连地堆放文件. 使用tar可以打包整个目录树,这使得它特别适合用于备份.归档文件可以全部还原,或从中展开单独的文件和目录.备份可以保存到基于文件的设备或磁带设备上.文件可以在还原时重定向,以便将它们重新放到一个与最初保存它们的目录(或系统)不同的目录(或系统).tar是与文件系统无关的,它可以使用在ex

百科知识 tar文件如何打开

tar 是什么文件格式,是干什么用的,用什么打开 tarball压缩格式,源于Linux的一个指令,Windows上可以用WinRAR打开 Linux的实用程序tar最初是为了制作磁带存档而设计的(把文件和目录复制到磁带中,然后从存档中提取或恢复文件),而现在的应用中可以把它用于任何设备,它是数据备份中最常用的命令之一. 下面具体介绍tar命令的使用方法: (1)格式:tar 参数 ...... (2)参数: c: 创建备份(Create) v: 表示回显模式(Verbose),将产生一系列备份

linux服务器备份工具(tar,cpio,dump)

Linux下的备份技术 1.备份前因考虑的因素 ● 可移植性(即在Red Hat Linux系统下执行的备份在另外一个系统上恢复的能力). ● 是否自动备份. ● 执行备份的周期. ● 需要把归档的备份保存多长时间. ● 用户界面的友好性(决定是否需要选择基于GUI界面的工具还是基于文本的). ● 是否需要使用压缩技术.直接复制或者加密技术. ● 备份介质(需要从价格.性能.存储能力上考虑). ● 是否远程备份或网络备份. ● 是保存一个文件.一个子目录还是整个系统. 2.备份选择的策略 需要确

CentOS下使用tar备份

tar是一个已移植到Linux中的经典UNIX命令.tar是Tape ARchive(磁带归档)的缩写,最初设计用于将文件打包到磁带上. 它是一个基于文件的命令,它本质上是连续地.首尾相连地堆放文件. 使用tar可以打包整个目录树,这使得它特别适合用于备份.归档文件可以全部还原,或从中展开单独的文件和目录. 备份可以保存到基于文件的设备或磁带设备上.文件可以在还原时重定向,以便将它们重新放到一个与最初保存它们的目录(或系统)不同的目录(或系统). tar是与文件系统无关的,它可以使用在ext2.

centos备份与还原

dump备份restore还原dd数据备份tar备份scpmkisofs镜像文件制作 dump备份 1.dump主要用于备份整个文件系统备份,虽然也可以备份单一目录,但是对目录文件支持不足,单一目录还是需要使用打包压缩的方式进行备份.  dump是功能上制定等级,也就是可以进行增量备份 dump等级分为0-9,10个等级,0为完全备份,1是在0的基础上惊醒增量备份,一次类推. 当待备份的数据为单一文件系统 可以利用了level 0~9进行备份,同时可以使用dump完整功能 当待备份的数据只是目录

Linux安装和配置Vim7.4

一.简介 Vim是一个类似于Vi的文本编辑器,不过在Vi的基础上增加了很多新的特性,Vim普遍被推崇为类Vi编辑器中最好的一个,事实上真正的劲敌来自Emacs的不同变体.1999 年Emacs被选为Linuxworld文本编辑分类的优胜者,Vim屈居第二.但在2000年2月Vim赢得了Slashdot Beanie的最佳开放源代码文本编辑器大奖,又将Emacs推至二线, 总的来看, Vim和Emacs同样都是非常优秀的文本编辑器. 本文介绍CentOS环境下,Vim7.2升级Vim7.4的方法.

【vim环境配置】详细实录

[写在前面] 以下的所有内容主要参照: https://github.com/yangyangwithgnu/use_vim_as_ide . 原blog作者写的非常用心,建议大家都去看看.(个人觉得通过这个blog大大提升了学习vim配置环境的效率,因此给作者捐了顿外卖的钱)这个随笔就是学习上述blog内容的辅助记录,并不能代替学习原著:把学习过程中遇到的一些坑列出来,初步做一下知识沉淀. 以前我个人的学习理念是“重剑无锋.大巧不工”,瞧不上这些快捷键之类的“奇技淫巧”.但是,打磨完了vim的

vim安装及配置

学习linux会使用vim编写c/c++代码很必要,vim加上一些必要的插件可以使开发效率提升,但是在网上查的资料都互相抄袭而且说的不太详细,决定自己简单总结一下. 没有用linux自带的vim,从官网下载的源码 ftp://ftp.vim.org/pub/vim/unix/vim-7.3.tar.bz2 解压缩,编译 tar -xvf vim-7.3.tar.bz2 cd vim73 ./configure make makeinstall 安装到默认路径,我没有关心安装到了哪里 然后在roo

ubuntu vim 7.4 编译安装

作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4137402.html 1.到官网 http://www.vim.org/download.php#unix vim-7.4.tar.bz2包 2.打开终端,通过命令行解压缩,输入 tar jxf vim-7.4.tar.bz2 此时会在当前目录下生成vim73文件夹 3.继续在终端输入 cd vim74 cd src ./configure 经过前面几步,会在/vim74/src目录下生成