The tar command creates, updates, examines, and unpacks archives.
- To create an archive file with tar:
$ tar -cf output.tar [SOURCES]
The c option creates a new archive and the f option tells tar the name of a file to use for the archive. The f option must be followed by a filename:
$ tar -cf archive.tar file1 file2 file3 folder1 ..
- The -t option lists the contents of an archive:
$ tar -tf archive.tar
file1
file2
- The -v or -vv flag includes more information in the output. These features are called verbose (v) and very-verbose (vv). The -v convention is common for commands that generate reports by printing to the terminal. The -v option displays more details, such as file permissions, owner group, and modification date:
$ tar -tvf archive.tar
-rw-rw-r-- shaan/shaan 0 2013-04-08 21:34 file1
-rw-rw-r-- shaan/shaan 0 2013-04-08 21:34 file2
The filename must appear immediately after the -f and it should be the last option in the argument group. For example, if you want verbose output, you should use the options like this:
$ tar -cvf output.tar file1 file2 file3 folder1 ..
$ tar -cvf output.tar file1 file2 file3 folder1 ..