linux tar - 压缩解压
【基本介绍】
今天遇到要添加文件到tar文件里面,所以在这里介绍tar的一些用法。
【参数介绍】
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
-r, --append
append files to the end of an archive
-t, --list
list the contents of an archive
-x, --extract, --get
extract files from an archive
-C, --directory=DIR
change to directory DIR
-f, --file=ARCHIVE
use archive file or device ARCHIVE
-j, --bzip2
filter the archive through bzip2
-p, --preserve-permissions
extract information about file permissions (default for superuser)
-v, --verbose
verbosely list files processed
-z, --gzip
filter the archive through gzip【常用例子】
1.创建归档文件
tarcvfarchive_name.tardirname/
c–createanewarchive
v–verboselylistfileswhichareprocessed.
f–followingisthearchivefilename
2.创建解压gzip归档文件
tarcvzfarchive_name.tardirname/
z–filterthearchivethroughgzip
.tgzissameas.tar.gz
tarxvfzarchive_name.tar.gz
3.创建解压bzipped归档文件
tarcvfjarchive_name.tar.bz2dirname/
.tbzand.tb2issameas.tar.bz2
tarxvfjarchive_name.tar.bz2
4.显示归档文件内容但是不解压
tartvfarchive_name.tar(归档文件)
tartvfzarchive_name.tar.gz(压缩gzip归档文件)
tartvfjarchive_name.tar.bz2(压缩bzip归档文件)
5.解压单一文件或者目录从tartar.gztar.bz2
tarxvfarchive_file.tar/path/to/file
tarxvfzarchive_file.tar.gz/path/to/file
tarxvfjarchive_file.tar.bz2/path/to/file
tarxvfarchive_file.tar/path/to/dir/
tarxvfzarchive_file.tar.gz/path/to/dir/
tarxvfjarchive_file.tar.bz2/path/to/dir/
6.解压一组文件从tartar.gztar.bz2
tarxvfarchive_file.tar--wildcards'*.pl'
7.添加文件或者目录到已经有的归档文件中
tarrvfarchive_name.tarnewfile
tarrvfarchive_name.tarnewdir/
不能对已经压缩过的归档文件进行此操作,必须先解压然后再添加文件/目录然后再压缩
gunziparchive.tar.gz
tarrvfarchive.tarnewfile
gziparchive.tar
8.压缩后删除源文件
tarzcvfarchive.tar.gznewfile--remove-files
【参考引用】
http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/