Linux tar command Help and Examples

April 24, 2019

Comments

Adsense

Adsense

Adsense

Adsense

Tar is the most important command for Linux administrator and data backup engineer. Almost every day, we use this command to take the backup of a file or directory, moving data from a server to another, etc.

Tar stands for Tape archive.

Linux tar command most widely used for backup and archive data.

It is essential to archive multiple files and directory into a single file.

Here some examples of tar command which is used by System Administrator every day.

tar command syntax:
tar [options] [archive-file] [file or directory to be archived]

In this article, we will check how to use the tar command in your favorite Linux machine by using these three examples.

  1. Use tar command to create ‘tar’ archive file
  2. Use tar command to create tar.gz archive file
  3. Extract tar archive file

Examples:

Use tar command to create ‘tar’ archive file

You can create a tar archive file by using the option “-cvf” as shown below:

# tar -cvf linuxconcept-14-09-19.tar /home/linuxconcept/

The options described as:

c – it is used to create a new “.tar” archive file.
v – it is use to get the output of command verbosely
f – it applies to give the file name for the archive file.

Use tar command to create tar.gz archive file

You can create a gzip archive file with extension tar.gz using the “tar” command with option “z”.

For example, here we create a tar.gz archive file for linuxconcept home directory, as shown below:

# tar cvzf Linuxconcept-14-09-19.tar.gz /home/linuxconcept
OR
# tar cvzf Linuxconcept-14-09-19.tgz /home/linuxconcept

The files with extension “tar.gz” and “.tgz” are similar.

Extract tar archive file

To extract “tar” file need to use option “x” with tar command, as shown below:

# tar -xvf linuxconcept-14-09-19.tar

If you want to extract files in any specific directory, you can use the option “-C” to specify the directory when a file should extract, as shown below:

# tar -xvf linuxconcept-14-09-19.tar -C /home/linuxconcept/videos/
Satish Kumar

Satish Kumar

I am Satish Kumar, Founder of LinuxConcept. Linux and F.O.S.S enthusiast, love to work on open source platform and technologies.

Adsense

Adsense

Adsense

Adsense

Adsense

Adsense

Adsense

Adsense

Adsense

Related Posts

The 30 most useful Linux commands

This article will introduce some practical and common Linux or Unix command , which is the Linux system administrators normally use the command . This article is not a complete list, but a brief list of commands that can be useful...

15 Practical examples of tcpdump command

15 Practical examples of tcpdump command

The tcpdump is the most essential and powerful command-line network packet sniffing tool. We use it to analyze network packets, capture or filter TCP/IP packets that transferred and received over the network on a specific network interface. It is available in almost...

15 Useful “df” Commands to Check Disk Space in Linux

15 Useful “df” Commands to Check Disk Space in Linux

There are several Linux tools available on the internet to check disk space utilization; we can use any of them. But, Linux has a best built-in command-line utility called “df”. The “df” is the short form of “disk filesystem”, we can get detailed information on used...

0 Comments

0 Comments

Submit a Comment

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

17 + twenty =

News & Updates

Join Our Newsletter

Adsense

Adsense

Adsense

Adsense