使用Linux命令行归档文件
存檔文件 (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中的壓縮技術(shù) ) ? 我們將學(xué)習(xí)檔案。 我們更喜歡壓縮,因?yàn)樗梢苑奖愕赝ㄟ^(guò)網(wǎng)絡(luò)發(fā)送壓縮文件,但有時(shí)并不是分開(kāi)壓縮多個(gè)文件的明智之舉,但是作為單個(gè)實(shí)體,我們可以肯定在一行中壓縮多個(gè)文件,但在核心中,所有文件是獨(dú)立壓縮的。
Archiving is the solution to this problem. The UNIX utility to archive files is tar, that is TApeaRchive.
存檔是解決此問(wèn)題的方法。 用于歸檔文件的UNIX實(shí)用程序是tar ,即TApeaRchive 。
Tar has 3 modes those are:
Tar有3種模式,分別是:
Create: which is a new archive from a group of files
創(chuàng)建:這是來(lái)自一組文件的新存檔
Extract: means getting one or more files from the archive
提取:表示從存檔中獲取一個(gè)或多個(gè)文件
The list: which shows the content of the archive without extracting it.
列表:顯示存檔的內(nèi)容而不提取它。
Our operations and command for archiving includes above three modes and will discuss throughout this article.
我們的歸檔操作和命令包括上述三種模式,并將在本文中進(jìn)行討論。
A tar file is also called a tarball, now let's dive into the practical thing.
tar文件也稱為tarball,現(xiàn)在讓我們深入了解實(shí)際情況。
示例1:創(chuàng)建模式 (Example 1: Create mode)
Explanation
說(shuō)明
Creating a Tarball(at least) requires 2 options, here we used 'c' and 'f' :
創(chuàng)建一個(gè)Tarball (至少)需要兩個(gè)選項(xiàng),這里我們使用了'c'和'f' :
c: create an archive file
c:創(chuàng)建一個(gè)存檔文件
f: tells tar to expect a file name as next argument.
f:告訴tar將文件名作為下一個(gè)參數(shù)。
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行中,我們創(chuàng)建了擴(kuò)展名為.tar的tar文件,并對(duì)我們選擇的所有文件使用了通配符(可以使用多個(gè)文件名,也可以使用兩個(gè)文件名)。
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的第一個(gè)選項(xiàng)始終是它的模式,在這里先創(chuàng)建( 'c' ),然后創(chuàng)建'f' ,在此我們?cè)趖ar文件名之后傳遞文件名。
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本身對(duì)其進(jìn)行顯式壓縮。
.minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}} .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}}示例2:壓縮 (Example 2: Compressing)
Explanation
說(shuō)明
In the above example, we used 3 option format of tar, for compression with achieving.
在上面的示例中,我們使用了tar的 3個(gè)選項(xiàng)格式,以實(shí)現(xiàn) 壓縮 。
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行中,第一個(gè)選項(xiàng)是創(chuàng)建模式,第二個(gè)“ z”用于gzip (我們可以將“ j”用于bzip2 ),第三個(gè)用于文件參數(shù)。 使用gzip壓縮tar的格式為.tar.gz或.tgz (對(duì)于bzip2 ,格式為.tar.bz或tbz )。
示例3:列表模式 (Example 3: List mode)
In the above sample, the command used is:
在上面的示例中,使用的命令是:
tar –tzvf filenameWhere, –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選項(xiàng)用于歸檔文件中的列表文件, z表示gzip ( j表示bzip2 ), v表示冗長(zhǎng) ,即屏幕上將顯示的內(nèi)容是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命令的情況下,選項(xiàng)的位置在Linux命令行中并不重要,但我們始終需要在最后保留–f選項(xiàng),因?yàn)樵趂之后需要一個(gè)文件名。
Recommended Articles:
推薦文章:
Make Utility (MakeFile) in Linux
在Linux中制作實(shí)用程序(MakeFile)
Compression techniques in Linux
Linux中的壓縮技術(shù)
ZIP files on command line in Linux
Linux中命令行上的ZIP文件
翻譯自: https://www.includehelp.com/linux/archiving-files-using-linux-command-line.aspx
總結(jié)
以上是生活随笔為你收集整理的使用Linux命令行归档文件的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 数据库数据规范化看不懂_数据库管理系统中
- 下一篇: linux用户组管理命令_Linux用户