Manipulate compressed files without extracting

compress_compgz or bz2 are very common compression formats on Linux. How do you read a gzip or bzip2 compressed text file? Or how can you list the files in an archive without extracting it? Fortunately the packages tar, gzip and bzip2 come with a set of handy utility programs which can do these for you. In this article we will take a peek into how those utilities work.

  • Modern tar doesn’t need you to indicate the archive format for extraction:
    $ tar -xvf archive.tar(.gz/.bz2)
  • Neither does vim! You can open an archive in vim:
    $ vim archive.tar(.gz/.bz2)
  • List the files in an archive:
    $ tar -tvf archive.tar(.gz/.bz2)
  • cat the files in an archive:
    $ zcat archive.tar.gz //gzip file
    $ bzcat archive.tar.bz2 //bzip2 file
  • Compare archives:
    $ zcmp/zdiff archive.tar.gz //gzip file
    $ bzcmp/bzdiff archive.tar.bz2 //bzip2 file
    //cmp is a tool to compare files byte by byte
  • grep some text:
    zgrep/zegrep/zfgrep //gzip file
    bzgrep/bzegrep/bzfgrep //bzip2 file
  • We are more or less done:
    zmore, zless //gzip file
    bzmore, bzless //bzip2 file

So think twice before you start extracting that huge archive file next time!


Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s