In: Computer Science
Linux
What is the tar command?
a. Can you compress files using tar? Please explain how and provide a brief example.
b. How do you create a tar file? Please provide an example.
c. How do you extract files in a tar format? Please provide an example.
Q Answer
#The tar command is used to create, maintain, modify and extract files which are archived in the tar format.
The tar stands for tape archive and it is an archiving file format just like a zip file. The tar command in Linux is one of the important command which provides archiving functionality in Linux. It allows us to quickly access a collection of files and placed them into a highly compressed archive file commonly called tarball, or tar, gzip, and bzip in Linux. The algorithm used for compressing of .tar.gz and .tar.bz2 are gzip or bzip algorithms respectively.
# To compress file using tar following command is used
tar -czvf name-of-archive.tar.gz /path/to/directory-or-file.
-c: Create an archive.
-z: Compress the archive with gzip.
-v: Display progress in the terminal while creating the archive,
also known as “verbose” mode. The v is always optional in these
commands, but it’s helpful.
-f: Allows you to specify the filename of the archive.
# how to create tar file in Linux using command line
procedure
# how to extract file in tar format
If You want to extract the contents of the archive to a specific
directory.
You can do so by appending the -C switch to the end of the
command.
For example, the following command will extract the contents of the
archive.tar.gz file to the /tmp directory.
tar -xzvf archive.tar.gz -C /tmp