9951 explained code solutions for 126 technologies


cli-tarHow do I tar and compress a file in Unix?


Tarring and compressing a file in Unix is a two step process. First, the file is tarred using the tar command. Then, the tar file is compressed using a compression utility, such as gzip or bzip2.

For example, to create a tar file of the file myfile.txt and compress it with gzip, use the following command:

tar -czvf myfile.tar.gz myfile.txt

The output of this command will be:

myfile.txt

The parts of this command are:

  • tar: The command to create a tar file
  • -czvf: Options used to compress the file with gzip and create a verbose output
  • myfile.tar.gz: The name of the tar file that will be created
  • myfile.txt: The file that will be tarred and compressed

For more information on using the tar command, see the GNU Tar Manual.

Edit this code on GitHub