可用选项列表
- c – create an archive file.
- x – extract an archive file.
- v – show the progress of the archive file.
- f – filename of the archive file.
- t – viewing the content of the archive file.
- j – filter archive through bzip2.
- z – filter archive through gzip.
- r – append or update files or directories to the existing archive files.
- wildcards – Specify patterns in UNIX tar command.
分类讲解
行为
- -c 打包 可以同时使用压缩
- -r 追加 只能追加到未压缩包中,不能追加到压缩包中
- -x 解包 不论是否压缩都能直接解
- -t 列出 列出包里文件
打包可选压缩方式
- -z gzip
- -j bz2
其他
- -f 指定文件名,注意后面必须跟文件名,所以多个选项拼接必须放最后
- -v 展示详情
- -wildcards 通配符,用于解压部分文件
示例
打包
只打包不压缩
tar -cvf targetName.tar /home/jyw/some-file/
gzip压缩
tar -czvf targetName.tar /home/jyw/some-file/
bz2压缩
tar -cjvf targetName.tar /home/jyw/some-file/
解压
解压到当前目录
tar -xvf targetName.tar
解压到指定目录
tar -xvf targetName.tar -C ./output
列出包中文件
tar -tvf targetName.tar
解压单个文件
直接后面接上要解压出的单个文件即可
tar -xvf tarBz2.tar.bz2 test.txt