HomeLinuxThe best way to tar a Folder in Linux?

The best way to tar a Folder in Linux?

Linux affords a pre-installed ‘tar (tape archive)’ command utility software. It’s used for the compression and extraction of “.xz”, “gz”, “.tbz”, and “.bz2” extensions. It’s helpful to compress giant folders and information into an archive file. The compressed folders take much less storage to switch from one system to a different.

This publish pens down temporary particulars to tar a folder in Linux with the next highlights:

The best way to tar a Folder in Linux?

The creation of a tar folder is dependent upon its fundamental syntax which is outlined beneath:

$ tar cf [File_name.tar] [Directory/Folder to Archive]

The syntax comprises the next parameters:

  • tar: Represents the “tar” command line utility.
  • c: Creates the required tar file.
  • f: Specifies the created archive file identify.
  • tar: Identifies the compressed tar archive.
  • Listing/Folder to Archive: Exhibits folder identify that must be compressed.

By following the above syntax, tar the “Additional” listing having the next information and subdirectories:

Instance 1:  Create a “.tar” Folder

Create the “ComExtra.tar” easy compressed tar archive of “Additional” listing utilizing the above “tar” command syntax:

$ tar cf ComExtra.tar Additional

The “Additional” has been efficiently compressed right into a “ComExtra.tar” file.

Instance 2:  Create a “tar.gz” Folder

The “tar” command additionally helps the generally used gzip compression format having “tar.gz”, “tgz”, and “tar.gzip” extensions. For this function, “tar” affords the “-z (gzip format)” flag.

Now we compressed the “Additional” folder into the “tar.gz” compression format utilizing the command outlined beneath:

$ tar czf GzipExtra.tar.gz Additional

Append a tar Folder in Linux

As soon as the “tar” folder is created, it may well simply be custom-made or prolonged with out extraction.

Use the “r(append)” flag of the “tar” command to append the “Additional.tar” folder by including three information on its finish:

$ tar -rvf ComExtra.tar FileA.txt FileB.txt FileC.txt

The “three” desired information have been added into the “ComExtra.tar” folder that may be seen utilizing the “-v(verbose)” flag.

View a tar Folder in Linux

All of the tar information and folders may be displayed within the terminal by utilizing the “-t(record tar content material)” flag on this manner:

$ tar -tf GzipExtra.tar.gz

The output is similar because the output from the “-v” flag.

Extract a tar Folder in Linux

The “tar” command additionally helps the extraction of “tar” information/folders into the present working listing or the precise listing.


The essential syntax to extract the “tar” file is written right here:

The “x” flag denotes the extraction of the tar archive.

Instance 1: Extract “.tar” Folder in PWD

To extract the “tar” folder within the present working listing merely make the most of the above syntax and specify the compressed “ComExtra.tar” folder within the terminal:

The compressed “ComExtra.tar” folder has been extracted.

Instance 2: Extract the “tar.gz” Folder in a Particular Listing

The “-C(–listing)” flag is helpful to extract the specified tar folder within the explicit location the place the consumer needs.

On this instance, the “GzipExtra.tar.gz” compressed archive positioned within the “House” is extracted into the “Pattern” listing on this manner:

$ tar xzf GzipExtra.tar.gz -C /residence/linuxhint/Pattern/

The output verifies that “GzipExtra.tar.gz” has been utterly extracted into the “Pattern” listing.

Instance 3: Extract Particular File From “tar” Folder

Easy sort the identify of the desired file/subdirectory that you just wish to extract from the “tar” folder with the “tar” utility within the following manner:

$ tar xzvf GzipExtra.tar.gz Additional/Dir1

The “Dir1” listing has been extracted from the “GzipExtra.tar.gz” compressed file.


To tar a folder in Linux, customers can execute the “tar cf [File_name.tar] [Directory/Folder to Archive]” command. Utilizing this, you possibly can compress and decompress the tar folder. Moreover, customers can append, view, and extract a tar Folder in Linux. This publish has demonstrated a set of sensible examples that illustrates the creation and extraction of a tar folder in Linux.



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments