日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

使用Linux命令行归档文件

發(fā)布時間:2025/3/11 linux 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用Linux命令行归档文件 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

存檔文件 (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中的壓縮技術 ) ? 我們將學習檔案。 我們更喜歡壓縮,因為它可以方便地通過網絡發(fā)送壓縮文件,但有時并不是分開壓縮多個文件的明智之舉,但是作為單個實體,我們可以肯定在一行中壓縮多個文件,但在核心中,所有文件是獨立壓縮的。

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

    創(chuàng)建:這是來自一組文件的新存檔

  • 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,現(xiàn)在讓我們深入了解實際情況。

    示例1:創(chuàng)建模式 (Example 1: Create mode)

    Explanation

    說明

    Creating a Tarball(at least) requires 2 options, here we used 'c' and 'f' :

    創(chuàng)建一個Tarball (至少)需要兩個選項,這里我們使用了'c'和'f' :

    • c: create an archive file

      c:創(chuàng)建一個存檔文件

    • f: tells tar to expect a file name as next argument.

      f:告訴tar將文件名作為下一個參數(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)建了擴展名為.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的第一個選項始終是它的模式,在這里先創(chuàng)建( 'c' ),然后創(chuàng)建'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本身對其進行顯式壓縮。

    .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

    說明

    In the above example, we used 3 option format of tar, for compression with achieving.

    在上面的示例中,我們使用了tar的 3個選項格式,以實現(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行中,第一個選項是創(chuàng)建模式,第二個“ z”用于gzip (我們可以將“ j”用于bzip2 ),第三個用于文件參數(shù)。 使用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

    總結

    以上是生活随笔為你收集整理的使用Linux命令行归档文件的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。