Hack 48. Tar Command Basics

tar command (tape archive) is used to convert a group of files into an archive.

Syntax: tar [options] [tar-archive-name] [other-file-names]

How can I create a single backup file of all files and subdirectories under my home directory?

The following command creates a single archive backup file called my_home_directory.tar under /tmp. This archive will contain all the files and subdirectories under /home/jsmith.
o Option c, stands for create an archive.
o Option v stands for verbose mode, displays additional information while executing the command.
o Option f indicates the archive file name mentioned in the command.

# tar cvf /tmp/my_home_directory.tar /home/jsmith

How do I view all the files inside the tar archive?

Option t will display all the files from the tar archive.

# tar tvf /tmp/my_home_directory.tar

How do I extract all the files from a tar archive?

Option x will extract the files from the tar archive as shown below. This will extract the content to the current directory location from where the command is executed.