9951 explained code solutions for 126 technologies


cli-tarHow can I tar and gzip a file in one command?


The tar command can be used to tar and gzip a file in one command. To do this, use the -z option flag to compress the file using gzip. The syntax for this command is:

tar -zcvf <filename>.tar.gz <file>

This will create a <filename>.tar.gz file in the current directory.

Code explanation

  • tar: the command used to tar and gzip a file
  • -z: the option flag to compress the file using gzip
  • cvf: the options flags to create a tar file, verbose output, and specify the output file name
  • <filename>.tar.gz: the output file name
  • <file>: the name of the file to be compressed

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

Edit this code on GitHub