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.gz
in the current directory. The-z
flag indicates that the archive should be compressed with gzip. The-c
flag indicates that the archive should be created, and the-v
flag indicates that the progress should be verbosely listed to the console. -
You can also use the
-f
flag 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
-x
flag instead of the-c
flag:
tar -zxvf archive.tar.gz
-
This command extracts the contents of
archive.tar.gz
to the current directory. -
You can also use the
--list
flag to view the contents of the archive without extracting it:
tar -ztvf archive.tar.gz
- This command lists the contents of
archive.tar.gz
to 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 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 shell to tar and zip files?
- How do I use the Unix tar zip command?
- How do I create a tar.zip file in Unix?
- How do I use the command line to tar and zip files?
- How do I use gzip, tar, and zip to compress files?
- How do I use the command line to tar and zip a file?
- How do I use the Unix tar xzvf command?
- How do I use the command line to tar and zip a file?
See more codes...