Linux学习笔记-tar命令
常用参数
-c 创建新归档 --create
-x 提取内容 --extract
-v 显示详情 --verbose
-f 文件名 --file 必选 该参数通常在最右
-C 改变目录 --change
-t 查看压缩包内容 --list
常见使用方法
#打包文件
tar -cvf myfile.tar test1.txt test2.txt test3.txt
#提取到当前目录
tar -xvf myfile.tar
#提取到指定目录
tar -xvf myfile.tar -C /home
压缩
主要的三种压缩包
参数 | 作用 | 后缀 |
---|---|---|
-z | gzip | x.tar.zip |
-j | bzip2 | x.tar.bz2 |
-J | xz | x.tar.xz |
常用压缩方法
#用gzip的方式压缩
tar -zcvf myfile.tar.zip test1.txt test2.txt.test3.txt
#用bzip2的方式压缩文件
tar -jcvf mystyle.tar.bz2 mystyle.tar
#用xz方式压缩文件
tar -Jcvf mystyle.tar.xz mystyle.tar
解压缩
tar能自动识别文件的压缩格式,自动解压
tar -xvf mystlye.tar.zip
tar -xvf mystlye.tar.bz2
tar -xvf mystlye.tar.xz