Indiana University
University Information Technology Services
  
What are archived documents?
Login>>
Login

Login is for authorized groups (e.g., UITS, OVPIT, and TCC) that need access to specialized Knowledge Base documents. Otherwise, simply use the Knowledge Base without logging in.

Close

ARCHIVED: In Unix, how can I read a file that ends in .Z, .z, .gz, or .bz2?

A file whose name ends in .Z, .z, .gz or .bz2 has been compressed, so it takes up less disk space. Unfortunately, you cannot read compressed files the way you do normal files. You must first expand, or uncompress, the files. How you do that depends on the program used to compress the file in the first place.

Files whose names end in .Z were compressed with the compress program. To expand such a file, at the Unix prompt, enter: uncompress filename

Replace filename with the name of the file you wish to expand. It doesn't matter if you include the .Z in the filename.

Files ending in .z or .gz were compressed with gzip, a newer and improved program. To uncompress a gzipped file, at the Unix prompt, enter: gunzip filename

Replace filename with the name of the file you wish to expand. It doesn't matter if you include the .z or .gz in the filename.

If you don't have enough disk space to uncompress the file, or you only want to see the contents once and have the file stay compressed, you can send the contents of the file to the standard output (usually your terminal), by using the zcat command. For example, to read the uncompressed contents of myfile.gz one page at a time, enter: zcat myfile | more

Note: On some Unix systems, zcat may work only on .Z files, not .z or .gz files. If that seems to be true on your system, but the gzip command is installed, you can replace zcat myfile with gunzip -c myfile in the command above.

Files ending in .bz2 have been compressed with bzip2 . To uncompress these files, enter one of the following commands: bunzip2 filename.bz2 or bzip2 -d filename.bz2 Replace filename with the name of the file you wish to expand.

If, after you uncompress the files, you have a file whose name ends in .tar, you now have a tar archive, which is a way of collecting together several files, or even entire directories. To extract the files from an archive, at the Unix prompt, enter: tar -xvf filename.tar

Replace filename with the name of your file. If you don't see any error messages when you run the tar command, you may want to delete the tar archive so you do not waste disk space.

If you know in advance that you will be receiving a .tar file, and you want to save space and an extra step, you can combine uncompressing and extracting by entering: zcat filename | tar -xvf -

Be sure to include the  -  at the end of the command. If zcat does not work on .gz or .z files on your system, in the command above, replace zcat with gunzip -c . If the file was encoded with bzip2, replace zcat with bz2cat or bzip2 -dc .

For more information about the commands discussed above, you can refer to the Unix man pages. At the Unix prompt, enter one of the following: man tar man uncompress man zcat man gzip man bzip2

At Indiana University, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?

This is document afcc in domain all.
Last modified on February 15, 2011.

I need help with a computing problem

  • Fill out this form to submit your issue to the UITS Support Center.
  • Please note that you must be affiliated with Indiana University to receive support.
  • All fields are required.



Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.

I have a comment for the Knowledge Base

  • Fill out this form to submit your comment to the IU Knowledge Base.
  • If you are affiliated with Indiana University and need help with a computing problem, please use the I need help with a computing problem section above, or contact your campus Support Center.