gzip, bzip2, tar, and pipes example

 

gzip -dc filename.tar.gz |tar -x

This sample command uncompresses a compressed "tar.gz" file. The first part of the command for gzip uncompresses the file, leaving you tar file. Tar files are a single file that contains multiple files (but uncompressed). The "|" pipes the uncompressed information to the tar program which unpacks it into multiple files. You should end up with a directory called "filename" with all the included files in it. Bzip2 uses a compatible decompress tag to gzip, so you can use bzip2 -dc ... in the above for a .tar.bz2 archive.

See the man pages (e.g. "man tar", "man gzip") for more information.

To archive and compress a folder:

From: http://www.cs.duke.edu/~ola/courses/programming/tar.html

It's often more useful to tar a directory (which tars all files and subdirectories recursively unless you specify otherwise). The nice part about tarring a directory is that it is untarred as a directory rather than as individual files.

   tar cvzf foo.tgz cps100

  tar unpack: tar -xvf file.tar

I think this will compress a file to a new file (i.e. no overwrite) in Windows Gzip:

gzip c:test.txt -c > c:temptest.gz

Linux

Compress a file, name will automatically be original name + ".gz": gzip file-to-be-compressed.txt
Decompress: gzip -d file-to-decompress.txt.gz

 

View a gzipped file (e.g. a log file that has been rotated and compressed):

gzip -dc /var/log/maillog.1.gz | cat

Or use grep on the file in the gzip:

gzip -dc /var/log/maillog.1.gz | grep me@example.com

 

Unzip a ".zip" file - it's actually a lot easier than I expected:

unzip [filename] 

 

bzip2 -d water.tar.bz2

 

Tags: examples, extract, decompress, bzip2, tarball, gzip, grep, 

Related Scribbles:
  • Utilities
  • Linux Commands


  • ID: 119
    Author:
    leonard
    Date Updated:
    2019-02-17 01:54:51
    Date Created:
    2003-10-23 10:04:21

    Edit

    Comments?
     >> Leonard Chan's Homepage  >> Scribble Web  >> gzip, bzip2, tar, and pipes example
    leonard.lotus-land.ca is hosted by Perceptus Solutions Inc.