The tar command on linux allows you to compress a file using gzip and create a .tar.gz archive, as well as decompress it. The command requires a few options to work properly. In order to compress a file, use the following command:
tar -czvf archive-name.tar.gz /path/to/file
The same command can be used to compress a directory, rather than a file. According to documentation, the supplied options have the following effects:
- -c: create a new archive
- -z: filter the archive through gzip - that is compress the file
- -v: verbosely list files processed
- -f: use archive file or device ARCHIVE - which requires you to specify the archive file name
In order to decompress a .tar.gz archive, use this command:
tar -xzvf archive-tar.gz
There is once difference with creating a new archive:
- -x: extract files from an archive