cli-tarHow do I use tar to compress only directories in a Unix system?
tar
is a Unix utility used to create and manipulate tar archives. To compress only directories using tar
, use the -z
flag for gzip compression and the -C
flag to specify the directory containing the files to be archived. For example:
tar -zcvf archive.tar.gz -C /path/to/directory .
This command will create an archive named archive.tar.gz
containing all the files and directories in /path/to/directory
.
The parts of the command are as follows:
tar
: the command to create and manipulate tar archives-z
: flag to enable gzip compression-c
: flag to create an archive-v
: flag to enable verbose output-f
: flag to specify the output file name-C
: flag to specify the directory containing the files to be archivedarchive.tar.gz
: the name of the output file/path/to/directory
: the directory containing the files to be archived.
: the current directory
Helpful links
More of Cli Tar
- How do I use the command line to tar and zip files?
- How do I use the Unix tar zip command?
- How can I use tar commands to zip a file?
- 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 create a tar.zip file in Unix?
- 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 command line to tar and zip a file?
- How do I use the command line to tar and distribute files?
See more codes...