Archiving with tar

The tar command can be used to archive files. It was originally designed for storing data on tape archives (tar). It allows you to store multiple files and directories as a single file. It can retain all the file attributes, such as owner, permissions, and so on. The file created by the tar command is often referred to as a tarball.

Getting ready

The tar command comes by default with all UNIX like operating systems. It has a simple syntax and is a portable file format. Let's see how to do it.

tar has got a list of arguments: A, c, d, r, t, u, x, f, and v. Each of these letters can be used independently for different purposes corresponding to it.

How to do it...

To archive files with tar, use the following syntax:

$ tar -cf output.tar ...

Get Linux Shell Scripting Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.