Technology and General Blog

Tape Archive or tar is a file structure for producing data files and directories into an archive though preserving filesystem info these kinds of as permissions. We can use the tar command to make tar archives, extract the archives, perspective files and directories stored in the archives, and append information to an present archive. Tar is a very simple still effective archiving utility.

This manual will walk you by way of creating and extracting tar archives on your Linux machine.

Put in Tar

In most Linux distributions, you will have tar pre-put in. Even so, in scenario you really don’t. If that’s your scenario, use the commands:


Use apt package supervisor as:

$ sudo apt-get put in tar


On Arch-centered distributions:


On REHL Family members, use yum as:

Tar File Formats

Tar supports uncompressed and compressed archives. Widespread extensions of the tar archives consist of:

  • .tar – A uncooked tar file.
  • .tar.gz, .tgz, .tar.gzip – Gzip tar archive.
  • .tar.bz2, .tbz, .tbz2, .tar.bzip2 – Bzipped tar archive.
  • .tar.Z, .Z, .taz – Compress tar archive.

Tar Primary Use

Working with tar in the command-line adopts the typical syntax:

$ tar [OPERATIONS] [OPTIONS] archive_name information/directories_to_archive

We start off by invoking the tar utility, adopted by the operation to complete. Operations may well incorporate:

  • -c – develop an archive
  • -x – extract archive
  • -t – reveals documents and directories in the archive.

Up coming, we move the choices to modify the utility’s conduct. These solutions can be -v for verbose or -f for archive name, -z to filter the archive by using gzip, and extra.

Finally, we go the archive title and the files and directories to insert to the archive.

How to Generate a Basic Archive

As we mentioned over, tar supports a range of compressions. To specify the kind of archive to generate, incorporate the preferred extension to the file title. For example, to build a gzipped tar archive, enter the filename as myarchive.tar.gz

Use the command underneath to produce the archive with the data files: file1, file2, file3, file4

$ sudo tar -c -f myarchive.tar file1, file2, file3

The -c tells tar to create a new archive. The -f flag specifies the file title.

How to Tar a Listing

To build a tar archive in a listing with all the information and sub-directories, move the listing route. From there, tar recursively finds all the documents and directories and adds them to the archive.

An instance command is:

$ sudo tar -c -f -z -v gzipped.tar.gz /property/ubuntu

You can suppress recursive listing archiving working with the –no-recursion flag.

How to Clearly show Contents of a tar Archive

To check out the files and directories in a tar archive, we use the -t selection. For instance:

$ tar -t -f gzipped.tar.gz

How to Extract a Tar Archive

To extract a tar archive, use the -x procedure flag for extraction. You can move any tar compression format these types of as gzip, lzma, bz2, and additional.

The most typical command for extracting tar archive information is:

$ tar -xvf archive.tar.[extension]

To extract a easy tar archive:

The command will extract the contents of the archive to the latest directory.

How to Extract a Specific File

In some situations, you may perhaps need to get certain documents from an archive. To do this, pass the filenames to the tar command separated by area.

For instance:

$ tar -xvf sample.wma details.txt backup.log

How to extract to a particular listing

As outlined, tar extracts the archive in the latest operating listing. To transform the listing in which the archived information are extracted, use the -C flag as:

$ mkdir ~/myarchive && tar -xvf myarchive.tar -C /home/ubuntu/myarchive

How to Append Information to an Archive

To insert data files to an present archive, we use the -r fo append followed by the name of the archive and the documents to incorporate.

For instance:

$ tar -rvf myarchive file1 file2 file3

How to Get rid of Files from an Archive

Using the –delete selection, we can clear away precise documents from an archive as:

$ tar -xvf –delete myarchive.tar file1 file2 file3


Tar is a worthwhile utility in Linux, most packages are archived in tar structure, and it is valuable to know how to use the tool.

Leave a Reply

Your email address will not be published. Required fields are marked *