tar 命令
2014-01-20 by dongnan
举个栗子
列出tar包内的文件
tar tzvf test.tar.gz
# 等效于less命令
less test.tar.gz
去掉 “/”
tar czvfP test.tar.gz
指定目录
tar zxvf test.tar.gz -C /tmp/
找到文件并打包
# 注意 `-T` 参数 与 `-` 标准输入
find ./ -type f -name '*.txt' | tar czf text.tar.gz -T -
排除目录
tar czvf test.tar.gz --exclude=/test/deploy /test
# 排除多个目录(docker、.git)
tar czfP ${docker_src_dir}${item_dir}.tar.gz --exclude=docker --exclude=.git -C $jenkins_dir $item_dir
命令参数
NAME
tar - manual page for tar 1.26
SYNOPSIS
tar [OPTION...] [FILE]...
DESCRIPTION
GNU `tar' saves many files together into a single tape or disk archive,
and can restore individual files from the archive.
-c, --create
create a new archive
-z, --gzip
filter the archive through gzip
-f, --file=ARCHIVE
use archive file or device ARCHIVE
-x, --extract, --get
extract files from an archive
-t, --list
list the contents of an archive
-v, --verbose
verbosely list files processed
-C, --directory=DIR
change to directory DIR
-P, --absolute-names
don't strip leading `/'s from file names
-T, --files-from=FILE
get names to extract or create from FILE
--exclude=PATTERN
exclude files, given as a PATTERN