Linux: tar Extract Files

Extract or Unpack a TarBall File

To unpack or extract a tar file, type:

 
tar -xvf file.tar
 

To save disk space and bandwidth over the network all files are saved using compression program such as gzip or bzip2. To extract / unpack a .tar.gz (gzip) file, enter (note -z option):

 
tar -xzvf file.tar.gz
 

To extract / unpack a .tar.bz2 (bzip2) file, enter (note -j option):

 
tar -xjvf file.tar.bz2
 

Where,

  • -x : Extract a tar ball.
  • -v : Verbose output or show progress while extracting files.
  • -f : Specify an archive or a tarball filename.
  • -j : Decompress and extract the contents of the compressed archive created by bzip2 program (tar.bz2 extension).
  • -z : Decompress and extract the contents of the compressed archive created by gzip program (tar.gz extension).

How Do I Extract A Single File Called foo.txt?

To extract a single file called foo.txt, enter:

 
tar -xvf file.tar foo.txt
tar -xzvf file.tar.gz foo.txt
tar -xjvf file.tar.bz2 foo.txt
 

You can also specify path such as etc/resolv.conf, enter:

 
tar -xvf file.tar etc/resolv.conf
tar -xzvf file.tar.gz etc/resolv.conf
tar -xjvf file.tar.bz2 etc/resolv.conf
 

How Do I Extract a Single Directory Called etc?

To extract a single directory called etc, enter:

 
tar -xvf file.tar etc
tar -xzvf file.tar.gz etc
tar -xjvf file.tar.bz2 etc
 

Sample outputs:

etc/
etc/pulse/
etc/pulse/default.pa
etc/pulse/client.conf
etc/pulse/daemon.conf
etc/pulse/system.pa
etc/xml/
etc/xml/docbook-xml.xml.old
etc/xml/xml-core.xml
etc/xml/catalog
etc/xml/catalog.old
etc/xml/docbook-xml.xml
etc/xml/rarian-compat.xml
etc/xml/sgml-data.xml
etc/xml/xml-core.xml.old
etc/xml/sgml-data.xml.old
etc/mail.rc
etc/Wireless/
etc/Wireless/RT2870STA/
etc/Wireless/RT2870STA/RT2870STA.dat
etc/logrotate.conf
etc/compizconfig/
etc/compizconfig/config
.....
...
....
etc/python/
etc/python/debian_config
etc/ConsoleKit/
etc/ConsoleKit/seats.d/
etc/ConsoleKit/seats.d/00-primary.seat
etc/ConsoleKit/run-session.d/
etc/ConsoleKit/run-seat.d/
etc/opt/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值