9951 explained code solutions for 126 technologies


cli-tarHow do I tar and gzip a file on a Mac?


To tar and gzip a file on a Mac, you can use the tar command. The syntax for using tar to create an archive and compress it in one step is as follows:

tar -czvf archive-name.tar.gz /path/to/directory-or-file

The flags used are:

  • -c: create an archive
  • -z: compress the archive with gzip
  • -v: show progress in the terminal while creating the archive
  • -f: allows you to specify the filename of the archive

The output should look something like this:

a directory-or-file
a directory-or-file/file1
a directory-or-file/file2

Once the command is complete, you will have a .tar.gz archive with the specified name in the current working directory.

For more information, see the following links:

Edit this code on GitHub