cli-tarHow do I compress a file into a GZIP tar.gz archive?
- Create a tar archive of the file or folder you want to compress:
tar -zcvf archive.tar.gz /path/to/file_or_folder
-
This command creates a tar archive named
archive.tar.gzin the current directory. The-zflag indicates that the archive should be compressed with gzip. The-cflag indicates that the archive should be created, and the-vflag indicates that the progress should be verbosely listed to the console. -
You can also use the
-fflag to specify the name of the archive:
tar -zcvf my_archive.tar.gz /path/to/file_or_folder
- To extract the contents of a gzip tar archive, use the
-xflag instead of the-cflag:
tar -zxvf archive.tar.gz
-
This command extracts the contents of
archive.tar.gzto the current directory. -
You can also use the
--listflag to view the contents of the archive without extracting it:
tar -ztvf archive.tar.gz
- This command lists the contents of
archive.tar.gzto the console.
Code explanation
**
-z: compress the archive with gzip-c: create a new archive-v: verbosely list the progress to the console-f: specify the name of the archive-x: extract the contents of the archive--list: list the contents of the archive without extracting it
## Helpful links
More of Cli Tar
- How do I use gzip, tar, and zip to compress files?
- How do I use gzip and tar in Linux?
- How do I use the command line to create a tar file?
- How do I compress a file using gzip and tar.xz?
- How can I fix an unexpected end of file error when compressing a file with tar and gzip?
- How can I use tar commands to zip a file?
- How do I use the command line to tar and zip a file?
- How do I use the command line to tar and zip files?
- How do I use the Unix tar xvf command to extract files?
- How do I use the Unix tar zip command?
See more codes...