9951 explained code solutions for 126 technologies


cli-tarHow do I compress a file using the Unix tar command?


The Unix tar command allows you to compress a file. The following example shows how to compress a file named file.txt:

tar -czvf file.tar.gz file.txt

This command creates a compressed file named file.tar.gz. The options used in this command are:

  • -c: This option creates a new tar archive.
  • -z: This option compresses the tar archive with gzip.
  • -v: This option prints the progress of the compression to the terminal.
  • -f: This option tells tar to read or create the archive specified by the file name.

The output of the command should look like this:

file.txt

For more information about the tar command, please see the following links:

Edit this code on GitHub