linux_wiki:archive_compress_unpack_and_uncompress_files_using_tar_star_gzip_and_bzip2

This is an old revision of the document!


Archive Compress Unpack And Uncompress Files Using Tar Star Gzip And Bzip2

General Information

About this page/how-to/script.


Options

  • -c ⇒ create new archive
  • -t ⇒ list contents of archive
  • -x ⇒ extract files from archive
  • -z ⇒ compress or decompress in gzip (depending upon if -x or -c was also passed)
  • -v ⇒ display files as they are processed
  • -j ⇒ use bzip2
  • -r ⇒ append/add file to the end of the existing archive
  • -u ⇒ update a file in an existing archive if the source is newer
  • -f ⇒ archive filename
  • –selinux ⇒ include selinux contexts

Archive and compress (using gzip) the /var/log directory

tar -cvzf logs.tar.gz /var/log


List contents of archive

tar -tf logs.tar.gz


Decompress and unpack at the same time to current directory

tar -zxvf logs.tar.gz


Decompress and unpack at the same time to a different existing directory

tar -zxvf logs.tar.gz -C /home/rjones/data/


Add a new file to an existing archive

tar -rvf logs.tar newlog.log

Install (usually not there by default)

yum install star


Archive and compress the /var/log directory (name it logs.tar.gz)

star -cz -f logs.tar.gz /var/log


List archive contents

star -t -f logs.tar


Decompress, unpack a bzip2 (star auto selects proper decompression type)

star -x -f logs.tar.bz2

Compress an archive

gzip logs.tar


Decompress an archive

gzip -d logs.tar.gz
OR
gunzip logs.tar.gz


Cat a compressed file (useful for rotated logs)

zcat messages.1.log.gz

Compress an archive

bzip2 logs.tar


Decompress an archive

bzip2 -d logs.tar.bz2
OR
bunzip2 logs.tar.bz2


Cat a compressed file (useful for rotated logs)

bzcat messages.1.log.bz2

  • linux_wiki/archive_compress_unpack_and_uncompress_files_using_tar_star_gzip_and_bzip2.1456804032.txt.gz
  • Last modified: 2019/05/25 23:50
  • (external edit)