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.

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

  1. 百科知识 tar文件如何打开

    tar 是什么文件格式,是干什么用的,用什么打开 tarball压缩格式,源于Linux的一个指令,Windows上可以用WinRAR打开 Linux的实用程序tar最初是为了制作磁带存档而设计的(把 ...

  2. tar.gz

    tar.gz,或者.tgz的文件一般是在UNIX下用tar和gunzip压缩的文件.可能的文件名还有.tar.gz等.gunzip是一种比pkzip压缩比高的压缩程序,一般 UNIX下都有.tar是一 ...

  3. Linux下编译安装Vim8.0

    什么是Vim? Vim 是经典的 UNIX 编辑器 Vi 的深度改良版本.它增加了许多功能,包括:多级撤销.格式高亮.命令行历史.在线帮助.拼写检查.文件名补完.块操作.脚本支持,等等.除了字符界面版 ...

  4. Ubuntu下deb文件及tgz文件安装

    dpkg 是Debian Package的简写,是为Debian 专门开发的套件管理系统,方便软件的安装.更新及移除.所有源自Debian的Linux发行版都使用dpkg,例如Ubuntu.Knopp ...

  5. gitlab基本维护和使用

    基本介绍 GitLab是一个自托管的Git项目仓库,可以自己搭建个人代码管理的仓库,功能与github类似. 安装 下载 gitlab下载地址: https://about.gitlab.com/do ...

  6. linux下编译安装vim7.4并安装clang_complete插件

    linux下编译安装vim7.4并安装clang_complete插件 因为debian里软件仓库中下载安装的vim是不支持python写的插件的(可以打开vim,在命令模式先输入:py测试一下),导 ...

  7. 在Linux操作系统下备份恢复技术的应用 转自https://yq.aliyun.com/articles/50205?spm=5176.100239.blogcont24250.9.CfBYE9

    摘要: 安全防护:在Linux操作系统下备份恢复技术的应用  原文参见:http://linux.chinaunix.net/techdoc/system/2005/12/19/925898.shtm ...

  8. 快速学习C语言三: 开发环境, VIM配置, TCP基础,Linux开发基础,Socket开发基础

    上次学了一些C开发相关的工具,这次再配置一下VIM,让开发过程更爽一些. 另外再学一些linux下网络开发的基础,好多人学C也是为了做网络开发. 开发环境 首先得有个Linux环境,有时候家里机器是W ...

  9. Debian7编译VIM7.4

    [ 另: vim7.4源码在vs2013的编译方法 ] 1 安装libncurses5库: apt-get install libncurses5-dev 2 安装gvim需要的库: 方法一: apt ...

随机推荐

  1. partprobe 和 partx 的用法

    partprobe: 用于重读分区表,当出现删除文件后,出现仍然占用空间.可以partprobe在不重启的情况下重读分区. 将磁盘分区表变化信息通知内核,请求操作系统重新加载分区表. -d 不更新内核 ...

  2. Qt可扩展窗口实现

    前言 有时候需要实现窗口可扩展,换句话说有一部分widget能够隐藏,显示,并且对话框大小可以随着widget变动而做出相应的变化:如图: 在点击CheckBox时,GroupBox_2能够显示,取消 ...

  3. leetcode 257. 二叉树的所有路径 包含(二叉树的先序遍历、中序遍历、后序遍历)

    给定一个二叉树,返回所有从根节点到叶子节点的路径. 说明: 叶子节点是指没有子节点的节点. 示例: 输入: 1 / \2 3 \ 5 输出: ["1->2->5", & ...

  4. Windows10内置Linux子系统初体验

    http://www.jianshu.com/p/bc38ed12da1dhttp://www.jianshu.com/p/bc38ed12da1d WSL 前言 前段时间,机子上的win10又偷偷摸 ...

  5. 20190526 - CentOS 7 中 安装 MySQL 8 并授权 root 远程访问

    1. CentOS 7 中 安装 MySQL 8 CentOS 7 中内置 MariaDB 建议升级一下用,性能好很多.但如果一定要用 MySQL 8,就得自己装. 坦白的说,Oracle 升级 My ...

  6. BUGKU (Mountain climbing)

    UPX壳,手脱后打不开,可能是在windows10脱壳的缘故吧.放在XP虚拟机上手脱可能会好,但是提示缺少dll.无奈,智能用工具了. 用的这个,感觉蛮好用的. 先打开程序.随便输入一个数,提示err ...

  7. 【HANA系列】对话SAP全球CEO孟鼎铭:未来最大的发展机遇属于中国中小企业

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]对话SAP全球CEO孟鼎铭:未来 ...

  8. LeetCode.1160-找到可以由给定字符组成的字符串(Find Words That Can Be Formed by Characters)

    这是小川的第411次更新,第443篇原创 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第262题(顺位题号是1160).你会得到一个字符串单词数组和一个字符串chars.如果字符串可 ...

  9. 今天发现一个Window系统服务增删改查神器:NSSM

    官网地址:https://nssm.cc Win10系统下这个:https://nssm.cc/ci/nssm-2.24-101-g897c7ad.zip 官方的帮助,英语的,可以大概看一下: htt ...

  10. 【VS开发】socket编程原理

    socket编程原理 1.问题的引入 1) 普通的I/O操作过程: UNIX系统的I/O命令集,是从Maltics和早期系统中的命令演变出来的,其模式为打开一读/写一关闭(open-write-rea ...