Linux中tar命令解压缩常见用法

本文详细介绍了Linux中tar命令的使用,包括如何打包、压缩、解压和查看档案文件内容。讲解了不同压缩选项如gzip和bzip2的用法,并提供了具体的命令行示例,如打包不压缩、gzip压缩、bz2压缩等操作。同时,还涵盖了使用通配符解压特定文件的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

可用选项列表

  • 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值