目录

    -c, --create Create a new archive.  Arguments supply the names of the files to be archived.
    -x, --extract, --get Extract files from an archive.
    -z, --gzip, --gunzip, --ungzip Filter the archive through gzip(1).
    -j, --bzip2 Filter the archive through bzip2(1).
    -f, --file=ARCHIVE Use archive file or device ARCHIVE.  If this option is not given, tar will first examine the environment variable `TAPE'.  If it is set, its value will be used as the archive  name.   Otherwise, tar will assume the compiled-in default.
    -t, --list List the contents of an archive.
    -v, --verbose Verbosely list files processed.

打包

不压缩

tar cvf filename.tar filename

压缩

  • gzip (*.tgz *.tar.gz)
    tar czvf filename.tgz filename
    
  • bzip2 (*.tbz2 *.tar.bz2)
    tar cjvf filename.tbz2 filename
    

解包

不压缩

tar xvf filename.tar

压缩

  • gzip (*.tgz *.tar.gz)
    tar xzvf filename.tgz
    
  • bzip2 (*.tbz2 *.tar.bz2)
    tar xjvf filename.tbz2
    

解包到指定目录

  • 方法一(目录需要是存在的)
    tar xf filename.tar -C dir
    
  • 方法二
    tar xf filename.tar --one-top-level=dir
    

查看包里的文件

tar tf filename.tar

参考资料