- tar命令用于对文件打包压缩或解压
- 格式:tar [选项 -C 指定解压到的目录] [文件]
- 打包并压缩文件:
tar -zcvf 压缩包名.tar.gz 文件名
[root@localhost testB]# ls
111.txt 222.txt
将111.txt文件通过gzip打包保存文件名111.tar.gz
[root@localhost testB]# tar zcvf 111.tar.gz 111.txt
111.txt
[root@localhost testB]# ls
111.tar.gz 111.txt 222.txt
[root@localhost testB]# rm -rf 111.txt
[root@localhost testB]# ls
111.tar.gz 222.txt
解压111.tar.gz到当前目录
[root@localhost testB]# tar zxvf 111.tar.gz
111.txt
[root@localhost testB]# ls
111.tar.gz 111.txt 222.txt
解压111.tar.gz到指定目录/root/testC下
[root@localhost testB]# tar -zxvf 111.tar.gz -C /root/testC/
111.txt
[root@localhost testB]# ll /root/testC/
总用量 4
-rw-r--r--. 1 root root 3 9月 7 15:23 111.txt