
The general command to compress a single file or directory in Linux is: tar -czvf.
#CENTOS UNTAR GZ ARCHIVE#
#How to Compress Multiple Files or Directories to a Single Archive We'll stick to the convention we used here in the rest of our examples, but keep in mind there is more than one way to specify tar options. While that is a common convention, it is not generally required. You'll notice that we're using - before specifying our tar switches. Note: There's more than one way to specify tar switches. Instead, it would look similar to this tar: Removing leading `/' from member namesĪnd if there were no errors or characters that needed to be removed from the member names - for example, if we were compressing files in our current working directory - there would be no output. If we omitted the v switch and instead used the command tar -czf /pepper, the output would not include each file. The output will look similar to: tar: Removing leading `/' from member names Here is what each of those switches means:įor example, to compress the /pepper directory to an archive named, run this command: tar -czvf /pepper The general command to compress a single file or directory in Linux is: tar -czvf #How to Compress a Single File or Directory Using -J instead of -z will use xz instead of gzip.

Replacing -z with -j in the commands will use bzip2 instead of gzip. Note: In our examples, we'll focus on using gzip.

Generally, gzip and bzip2 are comparable from a compression and performance perspective, but gzip is more widely used.xz tends to give the best overall compression but also takes more time and compute resources. The table below details some of the basic differences between these compression tools. Gzip isn't the only compression program tar can use. tar's z switch makes the tar command use gzip. tar can use gzip to compress the files it archives. However, these tools are not mutually exclusive. Tar creates archives from multiple files while gzip compresses files. The basic difference between the two tools is: When dealing with Linux archives, you're likely to hear about tar and gzip, often in similar contexts. In addition to creating archives, tar can perform compression and decompression using several different compression utilities such as gzip and bzip2.

#CENTOS UNTAR GZ CODE#
In opensource and Linux communities, tarballs are one of the most common methods for distributing source code and other important files. Tar - short for "tape archive" - is a GNU command line tool for creating and extracting archives.Īn archive is a single file that includes multiple files or directories. We'll use Ubuntu 20.04 for all examples, but you can follow along on any Linux system that uses tar. In this article, we'll demonstrate how you can use the tar utility to archive, compress, and extract files on Linux systems. bz2 extension, there's a good chance it was created using the. If you've ever worked with "tarball" files that have the. Archiving, compressing, and extracting files are some of the most common tasks for a Linux administrator.
