存档文件 (Archiving Files)
As we already understand what Compression (Compression techniques in Linux) is? We shall learn about Archives. We prefer compression as it is convenient to send file compressed through a network but sometimes it is not a smart way to compress the multiple files separately but as a single entity, we can sure compress multiple files in a single line but in the core, all files are compressed independently.
众所周知, 什么是压缩( Linux中的压缩技术 ) ? 我们将学习档案。 我们更喜欢压缩,因为它可以方便地通过网络发送压缩文件,但有时并不是分开压缩多个文件的明智之举,但是作为单个实体,我们可以肯定在一行中压缩多个文件,但在核心中,所有文件是独立压缩的。
Archiving is the solution to this problem. The UNIX utility to archive files is tar, that is TApeaRchive.
存档是解决此问题的方法。 用于归档文件的UNIX实用程序是tar ,即TApeaRchive 。
Tar has 3 modes those are:
Tar有3种模式,分别是:
Create: which is a new archive from a group of files
创建:这是来自一组文件的新存档
Extract: means getting one or more files from the archive
提取:表示从存档中获取一个或多个文件
The list: which shows the content of the archive without extracting it.
列表:显示存档的内容而不提取它。
Our operations and command for archiving includes above three modes and will discuss throughout this article.
我们的归档操作和命令包括上述三种模式,并将在本文中进行讨论。
A tar file is also called a tarball, now let's dive into the practical thing.
tar文件也称为tarball,现在让我们深入了解实际情况。
示例1:创建模式 (Example 1: Create mode)
Explanation
说明
Creating a Tarball(at least) requires 2 options, here we used 'c' and 'f' :
创建一个Tarball (至少)需要两个选项,这里我们使用了'c'和'f' :
c: create an archive file
c:创建一个存档文件
f: tells tar to expect a file name as next argument.
f:告诉tar将文件名作为下一个参数。
In line 1, we created the tar file with .tar extension and used a wildcard for all the files we have selected (multiple file name or both can be used).
在第1行中,我们创建了扩展名为.tar的tar文件,并对我们选择的所有文件使用了通配符(可以使用多个文件名,也可以使用两个文件名)。
tar command consists of:
tar命令包含:
tar [options] tarname filename1 filename2 ...
The first option of tar always is its mode, here it was created ('c') then 'f' where we pass file names after the name ofthe tar file.
tar的第一个选项始终是它的模式,在这里先创建( 'c' ),然后创建'f' ,在此我们在tar文件名之后传递文件名。
In line 2, the size of includehelp.tar is slightly more than the files it contains, but it can be compressed either explicitly compressing it with gzip(or bzip2) or with tar itself.
在第2行中, includehelp.tar的大小略大于其包含的文件,但是可以使用gzip (或bzip2 )或tar本身对其进行显式压缩。
示例2:压缩 (Example 2: Compressing)
Explanation
说明
In the above example, we used 3 option format of tar, for compression with achieving.
在上面的示例中,我们使用了tar的 3个选项格式,以实现 压缩 。
In line 2, again the first option is to create mode, second one 'z' is for gzip (we can use 'j' for bzip2), and third for file argument. Format of compress tar with gzip is .tar.gz or .tgz(for bzip2, format will be .tar.bz or tbz).
在第2行中,第一个选项是创建模式,第二个“ z”用于gzip (我们可以将“ j”用于bzip2 ),第三个用于文件参数。 使用gzip压缩tar的格式为.tar.gz或.tgz (对于bzip2 ,格式为.tar.bz或tbz )。
示例3:列表模式 (Example 3: List mode)
In the above sample, the command used is:
在上面的示例中,使用的命令是:
tar –tzvf filename
Where, –t option is used for list files in archive and z for gzip (j for bzip2) and v is verbose that is whatever is happing will shown on screen and f for given filename includehelp.tar.gz (or .tbz).
其中, -t选项用于归档文件中的列表文件, z表示gzip ( j表示bzip2 ), v表示冗长 ,即屏幕上将显示的内容是hap ,给定文件名 includehelp.tar.gz (或.tbz )将显示f 。
Note:
注意:
Although the position of the option doesn't matter in Linux command line in case of tar command, we always need to keep –f option at the end because after f it expects a filename.
尽管在使用tar命令的情况下,选项的位置在Linux命令行中并不重要,但我们始终需要在最后保留–f选项,因为在f之后需要一个文件名。
Recommended Articles:
推荐文章:
Make Utility (MakeFile) in Linux
在Linux中制作实用程序(MakeFile)
Compression techniques in Linux
Linux中的压缩技术
ZIP files on command line in Linux
Linux中命令行上的ZIP文件
翻译自: https://www.includehelp.com/linux/archiving-files-using-linux-command-line.aspx