gzip bzip xzip zip
1.打包
[root@localhost ~]# tar -c[v]f etc.tar etc/ [相对路径]
2.解包
[root@localhost ~]# tar -x[v]f etc.tar
1.对于文件
1.gzip的压缩解压
gzip filename
gzip -d filename.gz
gunzip filename.gz
2.bzip2的压缩解压
bzip2 filename
bzip2 -d filename.gz
bunzip2 filename.bz2
[root@qfedu.com ~]# gzip -c file1 > /usr/local/file1.gz #压缩到指定位置(注意以.gz结尾)
[root@qfedu.com ~]# gunzip -c /usr/local/file1.gz > /opt/file1 #解压到指定位置(解压出的名字可以自定义)
-c, --stdout
2.对于目录
#打包压缩:
tar -czvf dirname.tar.gz dirname #gzip
tar -cjvf dirname.tar.bz2 dirname #bzip2
tar -cJvf dirname.tar.xz dirname #xzip
zip -q -r dirname.zip dirname #zip
#解压缩:
tar -x[z|j|J]f 包名
unzip 压缩包名
#解压到指定位置:
tar -xf etc.tar.gz -C /opt
unzip etc.zip -d /opt
3.打包到指定目录
[root@qfedu.com ~]# tar czf /tmp/`date +%F-%T`-etc.tar.gz /etc/ #将打包的文件放到/tmp目录下,并以当前时间开头命名
4.扩展-按时间创建文件或目录
# mkdir `date +%F`-upload
# touch file-`date +%F`.txt