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命令的语法。

原文地址:https://www.cnblogs.com/jmliao/p/12296515.html