Linux Commands

How to Use Tar CVF and Tar XVF in Linux Explained with Example Commands

In Linux, Tar is the abbreviation of the Tape Archive. This command is used to store multiple files into a single file, and share them easily. It is one of those commands in Linux that provides the archiving functionality in Linux. This command is used to compress and uncompressed the files into the directory. The different file formats including tar, gzip, and bzip can be created using the tar command.

In this tutorial, we will show you the use of Tar CVF and Tar XVF in Linux with examples

Use Tar CVF and Tar XVF in Linux Explained with Example Commands

The Tar CVF is used to create archive files in Linux. If you use only the tar command, the files are not archived, they are only compressed into a single file. The Tar CVF in the command has three arguments:

  • C is used to create archive files
  • V provides the progress output
  • F points to the filename

Let’s look at the general syntax for using the tar cvf command:

tar -cvf <tar_file_name.tar> <file1> <file2>

Note: You can use the * to add all the files of the current directory to the archive file.

In the example written below, we are creating an archive file with the name txtfiles.tar and adding two files in it including document1 and sample.

tar -cvf txtfiles.tar document1 sample

Use the ls command to check the created archive file:


To create a gzipped archive file, use the -z option with the CVF, the file will be created in the current directory with tar.gz extension:

tar -cvzf <foldername>.tar.gz <file1> <file2>

The gzipped is the archive file of the text files, here we are creating the archive file of document1 and sample:

tar -cvzf archivefiles.tar.gz document1 sample

Verify the formation of the file with the ls command:

Linux Tar XVF With Example Commands

The Tar XVF is used to extract files from the existing archive files. In the command, the XVF has three arguments, so what do they mean? The X is used to extract the files, V is used to display the progress and F refers to the files.

The syntax of the Tar XVF command is:

tar xvf <filename.tar>

In our case, we are extracting the txtfiles.tar in the documents. When you execute the command, it will display the names of the files present in the archive file.

tar xvf txtfiles.tar

To un-compress the gzipped file, use the xvzf with the file name:

tar -xvzf archivefiles.tar.gz

Bottom Line

The tar command is used to create an archive file in Linux that can be moved and shared with other users. This utility has many helpful functionalities including managing backups, extracting installation files, and compressing files that can be extracted using the different options. The cvf is used to create an archive file and when the file is created, xvf is used to extract the archive files.

About the author

Zainab Rehman

I'm an author by profession. My interest in the internet world motivates me to write for Linux Hint and I'm here to share my knowledge with others.