A Beginner’s Guide to tar Command

A Beginner’s Guide to tar Command

The tar function is the greatest commonly utilized operation for creating compressed backup data that can be readily transferred from one disc to the other or from one system to the other. Here is ‘A Beginner’s Guide to tar Command’.

The Linux command “tar” indicates tape archive, and it’s required by a lot of Linux/Unix computer programmers to preserve tape storage. In Linux, the tar program is designed to shred a group of documents and folders into a remarkably compressed archive folder known as tar or tarball, bzip, or gzip. 

You might be experiencing difficulties since “.tar” folders aren’t compressed; they’re a separate file format. It can be difficult to read a.tar file, specifically so because the program you can apply to access has so many parameters. We’ll show you how to relieve that difficulty in this guide. We’ll go through how to make a compressed document and how to access one on Linux with the tar function.

What is the definition of an archive file?

A repository or archive file is a collection of one or more than one file as well as information. Archive folders are employed to combine several data file types into a compact document for easier transport and preservation, or merely to compress content to save space.

The Linux command ‘tar’ refers to the tape archive, and it is employed to generate and retrieve Archive files. In Linux, the tar operator is an essential utility that offers archiving capability. We may employ the Linux tar function to produce, preserve, and edit encrypted and decompress Archive files.


tar [the options available] [archive-filename] [document or directory to be archived]


  • -c: Produces an Archive
  • -x: Retrieve the archive
  • -f: generates an archive with the specified filename.
  • -t: retrieves or shows files in an archived file
  • -u: inserts to a pre-existing folder and archives it.
  • -v: This shows a lot of information.
  • Appends the archive files with -A.
  • -z: zip instructs the tar program to produce a tar file employing gzip compression.
  • -j: Use tbzip to filter an archived tar file.
  • Confirm an archive file with  -W.
  • -r: update or create a new file or folder in an existing one.tar archive

What is the function of the tar command?

Tar is a system software program for archiving information into a single encoded format, known as a tarball, either for dissemination or recovery reasons. 

The tar function creates compressed archives that reflect a single document or a group of files. The extension of a tar file often called a “tarball,” a gzip file, or a bzip file, is.tar or.tar.gz.

You’ve merely downloaded a document with the “.tar” extension from the web. You attempt to unzip it with standard unzipping software, but it refuses to launch. What exactly is happening? In this post, we’ll go over how to generate backup data with (tar.gz, tar, and tar.bz2) compression, how to recover archive records, retrieve a specific folder, see file information, validate a file, append files or folders to a pre-existing archive folder, predict the volume of a tar archive folder, and more.

Advantageous preposition. Is it?

Tar is among the most commonly used Linux compressing functions. Tar has numerous advantages, which is why it is so popular among professionals. Here’s everything you’ll have to get begun.

Tar refers to Tape Archives, and it’s a document and directory compression program.

For most circumstances, employing tar to compress a file output in a.tar file. Gzip is used for subsequent compression, resulting in a.tar.gz file. The term comes from “tape archive,” because it was designed to transmit data to serial I/O systems that didn’t have their independent file structure. Numerous file system attributes, such as hostname, time and date, provenance, permissions, and directories organization, are included in the archive sets of data formed by tar.

You can compact and play with decompression with files through tar. Tar has a lot of alternatives, but there are a couple that you should keep in mind.

The benefits of tar include:

  • When it concerns compressing, tar does indeed have a high ratio of compression that is about 50%, meaning it can compress 50% effectively.
  • Minimize the volume of packed files and directories dramatically.
  • Tar makes no changes to the properties of documents or folders. While reducing, licenses and other aspects are preserved.
  • Tar is extensively accessible over most Linux distributions. This is accessible on Android firmware along with previous Linux versions that are compatible.
  • Quickly reduces and decompresses
  • Simple to be used

Whilst it assists us to comprehend the positives of tar, one issue to consider is during what circumstances should you utilize it?

  • If you’re operating on a Linux operating system and need to reduce files,
  • To move a large number of documents and directories from one system to the other.
  • Make a contingency plan of your webpage, information, and anything else that is important to you.
  • Compressing will take up less storage on your computer, allowing you to save storage.
  • Directories can be uploaded and downloaded.

The disadvantages on the way

What are tarbombs?

This is one of the limitations of tar. In hacking jargon, a tarbomb refers to a tar file that includes multiple documents that unzip to the current folder. By rewriting files with similar names in the current folder or combining files from different applications, such a tar archive can cause difficulties. The customer is forced to locate and remove several documents interleaved among the directory’s various contents, which is at best inconvenient. Such conduct on the behalf of the archive’s administrator is deemed poor manners.


One more issue with tar design is that it permits a few (potentially unique) documents in chronicle to have indistinguishable way and filename. When separating such files, typically the last form of a record overwrites the previous. 

This can make a non-express (unobvious) tarbomb which does not contain records with outright ways or alluding guardian indexes, yet at the same time aims to overwrite documents outside the current registry 

Access is granted at random.

For simulcasting to tape backup systems, the tar standard was created without centralized indexing or database of information for documents and their characteristics. To enumerate or retrieve data, the archive should be viewed in order. This results in an efficiency disadvantage for big tar archives, leaving them undesirable for applications that frequently demand random entry to particular files.

What is the tar command in Linux?

You may use the tar function to build compressed archives that include a particular document or collection of documents. Tarballs, gzip, bzip, and tar files are all terms for the storage media that result.

A tar file is a unique type of file that combines many files into one. It’s comparable to a.zip format in that it can contain several files, but it really is a separate file format. The suffix.tar or.tar.gz is used for tar files.

You may access, read, and generate tar files in Linux with the tar function.

Access files with the tar function

If you wish to access a tar archive file, simply use the following command:

tar -xzvf linux_files.tar.gz

The following is the output of this Linux command line execution:

x linux/

x linux/names.txt

x linux/app.txt

x linux/README.md

x linux/config/app.sh

You notify the tar function that you wish to retrieve data from an archive with the -xzvf parameters. That’s a good approach to recall this four-character sequence: it begins with x and permits you to retrieve data.

This function extracts the data of archive name.tar.gz into your current working folder by default. The “-C” flag at the conclusion of the operation can be used to prevent this behavior. This flag permits you to select a destination folder for the information of the tar folder:

tar -xzvf linux_files.tar.gz -C /home/nameofyourfolder/Documents

The archive will be extracted into a directory located in My Computer’s document folder on our Linux PC using this function.

View a File with the tar Command

When you receive a tar document, you could be tempted to read it right away. You won’t be able to view what’s in the document any other way. However, you can watch the document without downloading it to your machine. You can list the information of a tar folder without extracting its entire data to your machine using the command prompt:

tar -tvf linux_files.tar.gz

The following are the command returns

drwxr–r–  0 James  staff   0 Jun 12 11:03 linux/

-rw-r–r–  0 James  staff  89 Jun 12 09:04 linux/names.txt

-rw-r–r–  0 James  staff   2 Jun 12 09:57 linux/app.txt

-rwxr–r–  0 James  staff   0 Jun 12 08:06 linux/README.md

-rw-r–r–  0 James  staff   2 Jun 12 10:26 linux/config/app.sh

This function produces results that look identical to what you’d get from the Linux ls function. The ls function displays a directory’s documents. In this example, the data of the tar file is reflected in the collection of folders. It isn’t unlocked yet; we’ve merely had a look inside.

The above functions will output a table of all the contents in the tarball if we use the “-tvf” parameters. We can observe that all of the contents in the tarball are in a folder called “linux” in the instance previously. Every one of these files will be transferred into our machine when we read this file.

Command: tar Make a.tar file.

There are a plethora of documents in the Linux ecosystem that are kept in.tar.gz files. You’ve come to the perfect spot if you need to preserve some information inside one. Leveraging the tar function, you can simply compress files and folders into a unified tar file:

tar -czvf file_name.tar.gz /path/to/folder

How to Make Files and Directories Invisible?

Although having the ability to compress a whole folder is important, there may be times when you wish to compress a complete folder in addition to a single file. Use the “–exclude” parameter at the ending of your tar function to accomplish this:

tar -czvf linux_archive.tar.gz /home/nameofyourfolder/linux –exclude=/home/name your folder/linux/app.txt

Except for the file “app.txt,” all of it in the /home/name your folder/linux directory will be archived with this function. If we wish to omit all documents with a specific file suffix, we may use the “–exclude” flag in combination with a wildcard:

tar -czvf linux_archive.tar.gz /home/nameofyourfolder/linux –exclude=/home/name your folder/linux/*.txt

Apart from those that finish in “.txt,” all of the documents in our “linux” directory will be retained.

In Linux, what are wildcards?

A wildcard, sometimes known as a ‘wild character’ or a ‘wildcard character,’ is a mark that is designed to substitute or symbolize one or even more symbols. An asterisk (*), which indicates one or maybe more symbols, or a question mark (?), which indicates a solitary symbol, are the most common wildcards.

The instance,

To find a picture in the.png format, type: Just documents encapsulating the extension.png will be extracted from the archives file.tar. The –wildcards parameter instructs tar to understand wildcards in the filenames to be retrieved; the filename (*.png) is contained in single quotation marks to prevent the wildcard (*) from becoming extended improperly by the shells.

$ tar tvf file.tar –wildcards ‘*.png’

” * ” is applied instead of the name of the document in the above prompts to get all the documents in that folder.

Examples of Tar command

The Linux command ‘tar’ refers to the tape archive, and it is employed to generate and retrieve Archive files. In Linux, the tar operator is an essential utility that offers archiving capability. We may employ the Linux tar function to produce, preserve, and edit encrypted and decompress Archive files.

The step by step process with the help of the examples

1. Employing the -cvf parameter to create an uncompressed tar archive: This effectively leads to file.tar, which would be a tar file containing all.c files in the present working folder.

$ tar cvf file.tar *.c

Output : 




2. Employing the -xvf strategy to extract data from an archive: This function retrieves documents from a directory called Archives.

$ tar xvf file.tar

Output :  




3. Employing the parameter -z, compact the tar archive with gzip: This carries out the tasks of the file.tar.gz tar file, and that is the Repository of.c files.

$ tar cvzf file.tar.gz *.c

4. Employing the -xvzf parameter to retrieve a gzip tar archive *.tar.gz: This function extracts information from file.tar.gz files that have been tar compressed.

$ tar xvzf file.tar.gz

5. Using the -j strategy in Linux to create a compressed tar archive file: This function compresses and produces an archive file that is smaller than the gzip file size. Compressing and decompressing take longer than gzip.

$ tar cvfj file.tar.tbz example.cpp

Output :  

$tar cvfj file.tar.tbz example.cpp


$tar tvf file.tar.tbz

6. Untar a solitary tar document or a particular folder in Linux: Employing the -C parameter, this function untars a document in the existing folder or a given location.

$ tar xvfj file.tar 


$ tar xvfj file.tar -C 

7. In Linux, there are untar multiple.tar,.tar.gz, and.tar.tbz files: Several documents will be extracted or untarred from the tar, tar.gz, and tar.bz2 archives with this function. The function preceding, for instance, will extract “fileD” and “fileG” from the archive folders.

$ tar xvf file.tar “fileD” “fileG” 


$ tar zxvf file1.tar.gz “fileD” “fileG”


$ tar jxvf file2.tar.tbz “fileD” “fileG”

8. In Linux, measure the contents of any pre-existing tar, tar.gz, or tar.tbz files: The program above should show the volume of the archive folder in the unit of kilobytes (KB).

$ tar czf file.tar | wc -c  


$ tar czf file1.tar.gz | wc -c


$ tar czf file2.tar.tbz | wc -c

9. Updation should take place in the pre-existing tar file of Linux

$ tar rvf file.tar *.c

Output :  


10. Employing the -tf argument, display the information, and identify the tar file: This function will display a table of all archived files. In a tar file, we may also create a table for a particular substance.

$ tar tf file.tar

Output :  


11. Using the grep function with pipe to locate what we’re searching for: In greps from archived documents, this operation would only display for the specified text document or .png document.

$ tar tvf file.tar | grep “text to find” 


$ tar tvf file.tar | grep “filename.file extension”

12. To explore a tar file, we can specify a directory listing as an option: This function displays the metadata of the compressed documents.

$ tar tvf file.tar filename 

13. Employing the -tvf argument to see the archives

$ tar file.tar tvf


-rwxrwxrwx root/root       181 2021-04-12 03:20 os2.c

-rwxrwxrwx root/root       208 2021-04-12 03:20 os3.c

-rwxrwxrwx root/root       483 2021-04-12 03:20 os4.c


As you’ve seen, tar is indeed a very useful utility that every Linux user should be familiar with. Using the human tar function, you can dig deeper into the tar command’s instructional manuals. You can use the tar function to compress documents into tarballs, read tarball information, and unzip tarballs. Here are a few commands you can employ to deal with tar as a refresher:

Open a file with the command tar -xzvf [name of file].

View a file with the command tar -tvf [name of file].

Make a file with tar -czvf. [filename new file] [folders and documents to archive]

It seems you’re prepared to use the tar program like a true Linux expert!

A Beginner’s Guide to tar Command

Leave a Reply

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

Scroll to top