Linux Tar Commands

tar commands

Tar commands are commands that we use to do different tar operations using terminals.

Transferring files in a single unit is always better than sending in multiple files. In order to achieve this, we have to package the whole to a single file system. Usually, for this, we use it to archive the files. There are a lot of archive file formats such as zip, rar, tarballs, etc.

Tar is an archive file format just like rar and zip. Usually, tar archives are called tarballs. They are mostly used in Linux and Unix systems

The tar command is a widely used tool in Linux for creating, extracting and manipulating tar archives. Tar archives are used to combine multiple files into a single file for easier storage, transportation, and backup.

Whether you are a beginner or an experienced Linux user, learning how to use the tar command is an essential skill. In this post, we will cover the basics of the tar command and provide examples of how to use it to create, extract, and manipulate tar archives.

By understanding the various options and flags available with the tar command, you can more easily manage and organize your files, as well as create backups and share files with others. Whether you are working with a small number of files or a large archive, the tar command has the tools and capabilities you need to get the job done. So, it is an important command to know for any Linux user.

In order to package tar, we need to know tar commands. Once we are ready with the tar commands, then you just need a Linux terminal to package your files. Before diving into tar commands let’s understand the basic syntax that a tar command follows.

How to Fix Bash Command Not Found

Syntax

tar {options} {archive-file} {file or directory}

Options

By default, we need to specify at least one option.

Basic operations are:

  • List an archive
  • Create an archive
  • Extract an archive

Options :

  • -c : Used to Create an Archive
  • -x: Used to Exract an Archive
  • -f: Used to create archives with given name
  • -t: Used to display or list the files in the archive
  • -u: Used to archive and add it to an existing archive file
  • -v: Used to display verbose Information
  • -a: Used to concatenate the archives
  • -z: Zip, Used to create tar files using gzip
  • -j: Used to filter the archive tar using tbzip
  • -w: Used to verify an archive
  • -r: Used to update or add file to the existing tar file.\

Learn all the zip commands

Let’s see some examples:

Let linuxstro be the file.

Create

tar cvf Linuxstro.tar

This command creates a tar command called Linuxstro.tar.

Suppose in a directory there are multiple files with different formats and you just wanted to archive all .txt files. Yes, we can do that let’s see how?

tar cvf Linuxstro.tar *.txt

Now, this command makes an archive named Linuxstro with all .txt files only.

Now let’s see how to create a gzip archive.

tar cvzf Linuxstro.tar.gz

The output file will be Linuxstro.tar.gz

Now let’s see how to create a tbzip archive.

Tbzip is a compressed archive format. It is used to create fewer size archives.

tar cvfj Linuxstro.tar.tbz

Update existing Tar file.

In this example, we are updating the with all “.png” files.

tar rvf Linuxstro.tar *.png

Exract

Let the name of the archive be Linuxstro

tar xvf Linuxstro.tar

Let’s extract tar.gz

tar xvzf Linuxstro.tar.gz

Lets extract tar.tbz

tar xvfj Linuxstro.tar.tbz

Untar file in a specified directory

We use -c option for this operation.

tar xvf Linuxsro.tar -c path of the directory

Untar Multiple files from tar

File1, File2 represents the particular that needs to be extracted.

tar xvf Linuxsrto.tar "File1" "File2"

Untar a Particular format from the tar

In this example, we are searching and extracting all “.mov” files from the tar.

tar tvf Linuxstro.rar --wildcard '*.mov'

View archive using -tvf

By using this function, It gives more details about the files in tar

tar tvf Linuxstro.tar

Listing the tar using -tf

tar tf Linuxstro.tar

Search a tarfile with filename

This command list the file with their details.

tar tvf Linuxstro.tar Filename

These are the very basic Linux commands, That every Linux user should know.

Learn how to add Kali Linux tools on Ubuntu Click HERE

Conclusion

In conclusion, the tar command is a powerful and widely used tool for archiving and compressing files in Linux. By using the various options and flags available with the tar command, you can create, extract, and manipulate tar archives with ease.

Whether you are a beginner or an experienced Linux user, learning the tar command is an essential skill. By understanding how to use the tar command, you can more easily manage and organize your files, as well as create backups and share files with others.

Overall, the tar command is an essential tool for any Linux user, and by learning how to use it effectively, you can improve your productivity and streamline your workflows. Whether you are working with a small number of files or a large archive, the tar command has the tools and capabilities you need to get the job done.