存檔文件 (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