cli-tarHow do I use the command line to tar and zip files?
The command line can be used to tar and zip files using the tar
and gzip
commands. To tar a file, use the tar
command followed by the cvf
flags and the desired filename, e.g. tar cvf mytarfile.tar myfile.txt
. This will create a tar file named mytarfile.tar
containing the file myfile.txt
. To zip the tar file, use the gzip
command followed by the desired filename, e.g. gzip mytarfile.tar
. This will create a zipped tar file named mytarfile.tar.gz
.
Example code
tar cvf mytarfile.tar myfile.txt
gzip mytarfile.tar
Output example
mytarfile.tar.gz
Code explanation
tar
: the command used to create a tar filecvf
: flags used to create a tar filemytarfile.tar
: the desired filename for the tar filemyfile.txt
: the file to be tarredgzip
: the command used to zip a filemytarfile.tar.gz
: the desired filename for the zipped tar file
Helpful links
More of Cli Tar
- How do I use the command line to tar and distribute files?
- How do I use the Unix tar zip command?
- How do I use gzip, tar, and zip to compress files?
- How do I use the shell to tar and zip files?
- How do I use the command line to tar and zip a file?
- How do I use the Unix tar xvf command to extract files?
- 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 create a tar.zip file in Unix?
See more codes...