tar:最常用的压缩与解压缩工具
一、最常用的操作和参数选项
1、 最常用的3个操作 Operations
--create
-c 创建一个新的tar压缩文件,即压缩
--list
-t 列出压缩文件的内容
--extract
-x 从压缩文件中提取内容(一个或多个),即解压缩
2、最常用的2个选项 Options
--file=archive-name
-f archive-name 压缩文件的名字
这个option后面是要加参数的,即压缩文件的名字,所以我们简写很多个命令的时候把f放到最后,后面直接跟压缩文件名字
--verbose
-v 列出正在被tar操作的文件
verbose的意思是冗长的,啰嗦的,用两个v可以显示更详细的信息哦!例如:"-vv"
三、具体操作
1. 压缩
原型:
$ tar --create --verbose --file=afiles.tar apple angst aspic
简写一下:
$ tar -c -v -f afiles.tar apple angst aspic
最简洁形式:
$ tar -cvf afiles.tar apple angst aspic
apple angst aspic 是要被压缩的文件
2. 看压缩文件的内容
$ tar --list --file=collection.tar
输出会是这种:
blues
folk
jazz
要是想确认某个文件(比如folk)是不是在压缩文件里,可以这样
$ tar --list --file=collection.tar folk
folk
要想看详细信息,可以搭配“–verbose”使用:
$ tar --list --verbose --file=collection.tar folk
-rw-r--r-- myself/user 62 1990-05-23 10:55 folk
3. 解压缩
解压缩跟压缩不一样的地方只是操作不一样,我们把create(-c)换成extract(-x)就可以了
原型:
$ tar --extract--verbose --file=collection.tar
简写一下:
$ tar -x -v -f collection.tar
最简洁形式:
$ tar -xvf collection.tar
要想解压缩某个文件,直接吧文件名加到命令最后:
$ tar --extract --file=collection.tar blues
搭配verbose可以输出信息
$ tar -xvf music.tar practice/folk practice/jazz
practice/folk
practice/jazz
两个verbose可以输出详细信息
$ tar -xvvf music.tar practice/folk practice/jazz
-rw-r--r-- me/user 28 1996-10-18 16:31 practice/jazz
-rw-r--r-- me/user 20 1996-09-23 16:44 practice/folk
4.其他可能用到的操作operation
--append
-r
Appends files to the end of the archive.
--delete
Deletes members from the archive. Don’t try this on an archive on a tape!
5.其他可能用到的选项option
--directory=dir
-C dir
When this option is specified, tar will change its current directory to dir before performing any operations. When this option is used during archive creation, it is order sensitive.
--gzip
--gunzip
--ungzip
-z
This option tells tar to read or write archives through gzip, allowing tar to directly operate on several kinds of compressed archives transparently.
三、想详细了解请看官方Tutorial
官方Tutorial
https://www.gnu.org/software/tar/manual/tar.pdf
328

被折叠的 条评论
为什么被折叠?



