Linux – tar command

The linux ‘tar’ program (name derived from tape archive) is a useful utility for archiving/transmitting files. A ‘.tar’ file does not represent compressed files; it is a collection of files within a single uncompressed file. If the file is a ‘.tar.gz’ (also called ‘tarball’) or ‘.tgz’ file, it is a collection of files that are compressed. In the below examples, I always compress/decompress with the ‘z’ flag.

Tar command flags:
c – to create a tar file
t – table of contents; see the names of all files
x – extract the contents of the tar file
f – specifies the filename
z – use zip/gzip to compress the tar file or to read from a compressed tar file
v – verbose output

To tar and compress all ‘.pl’ and ‘.py’ files into a tarball file named ‘perlandpython.tgz’ use:

tar cvzf perlandpython.tgz *.pl *.py

To tar and compress a directory named ‘code’ recursively to a file named ‘perlandpython.tgz’ use:

tar cvzf perlandpython.tgz code

To see the ‘perlandpython.tgz’ tarball’s file table of contents use:

tar tzf perlandpython.tgz

To extract the contents of the ‘perlandpython.tgz’ tarball file use:

tar xvzf perlandpython.tgz

This entry was posted in Linux, Operating Systems and tagged , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

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


five + 4 =