tar命令排除某個文件夾


命令簡介

SYNOPSIS
       tar [OPTION...] [FILE]...
Common options:
       -f, --file=ARCHIVE
              use archive file or device ARCHIVE

       -j, --bzip2
              filter the archive through bzip2
       -z, --gzip
              filter the archive through gzip
       -v, --verbose
              verbosely list files processed
Main operation mode:
       -c, --create
              create a new archive
       -t, --list
              list the contents of an archive
       -x, --extract, --get
              extract files from an archive

打包多個文件(夾)

之前以為使用tar命令必須先把所有內容放到一個文件夾下,然后在對這個文件夾打包。其實,tar命令可以一次性對多個文件(夾)進行打包,非常便捷,例如:

#當前目錄下有A,B,C目錄和a,b,c文件,只想對A,B,a進行打包,命令如下:
tar czf foo.tar.gz A B a

排除文件(夾)

如果我們想對一個代碼倉庫打包,需要排除.git版本庫,因為其非常大,可以使用下面的命令:

tar czf foo.tar.gz --exclude=.git foo

注意:如果將上述命令寫為tar czf foo.tar.gz foo --exclude=.git,--exclude選項將不會生效,因為這不符合tar命令的語法。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM