The tape archive (tar) command was originally designed to back up filesystems to tape devices. Although many people now use the tar command to back up to non-tape devices, you should be aware of how to use tape devices as well. For the following examples, we assume that you do not have a tape drive in your system. The examples provided for the tar command place the tar ball (the result of the tar command) in a regular file; however, if you have a tape drive, you can just replace the filename with your tape device file.

To create a backup (or tar ball) with the tar utility, use the -c (create) option in conjunction with the -f (filename) option:

#tar -cf <filename_to_be_created> <filename_to_be backed_up>

The leading / characters are removed from the filenames, so instead of absolute pathnames being backed up, the pathnames are relative. This makes it easier to specify where the files are restored. Having the leading / would result in files always being stored in the exact same location. To see the contents of a tar ball, use the -t (table of contents) option in conjunction with the -f option, as shown below.

#tar -tf <filename>

You often want to see detailed information when listing the contents of the tar ball. Include the -v (verbose) option to see additional information, as shown in this command.

#tar -tvf <filename>

To extract all the contents of the tar ball into the current directory, use the -x (extract) option in conjunction with the -f option, as shown in the following command

#tar -xf <filename>

If you only wants to extract only a specific type of files, you can specify it at the end of the command. In the following example, I have specified that I only needs to extract all the “.doc” files from the tar ball.

#tar xvf <filename> –-wildcards ‘*.doc’


The following two tabs change content below.
Ruwantha Nissanka is a Professional Cyber Security Engineer from Sri lanka with having a demonstrated history of providing cyber security services for multiple organizations in Sri Lanka. He is a positive person who wants to believe the best in others and he likes to help, encourage people and make them feel good.