- 打包:
tar -cvf fileName.tar filePath- -c: 创建文件
- -v: 显示打包过程
- -f: 指定最终文件名
- 查看打包的文件内容:
tar -tvf fileName.tar- -t: 显示文件列表
- 打包并压缩为 gz:
tar -czvf fileName.tar.gz filePath- -z: 使用 gzip 进行压缩
- 解 gz 压缩:
tar -xzvf fileName.tar.gz filePath- -x: 提取文件内容
- 打包并压缩为 bz2:
tar -cjvf fileName.tar.bz2 filePath- -j: 使用 bz2 进行压缩
- 解 bz2 压缩:
tar -xjvf fileName.tar.bz2 filePath - 安装 bz2 压缩:
yum install bzip2 - 安装 gz 压缩:
yum install gzip - 参考:
[1] : How to Compress and Extract Files Using the tar Command on Linux
[2] : Archive under Linux (tar, gz, bz2, zip)
[3] : The Ultimate Tar Command Tutorial with 10 Practical Examples