Archiving with tar
The tar
command can be used to archive files, originally designed for storing data on Tape archives. It allows you to store multiple files and directories as a single file while retaining 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. In this recipe, we will learn how to create archives using tar
.
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. It supports these arguments: A
, c
, d
, r
, t
, u
, x
, f
, and v
. Each of these options can be used independently for different purposes corresponding to it.
How to do it...
We can use tar to create archives, and perform operations on existing archives. Let's see how:
To archive files with tar, use the following syntax:
$ tar -cf output.tar [SOURCES]
For example:
$ tar -cf output.tar file1 file2 file3 folder1 ..
To list files in an archive, use the
-t
option:$ tar...