How to use the tar command
Archiving files with “tarâ€
The
"tar" command allow you to regroup several files to store them in a single file, still remaining uncompressed.
Archiving folder (or directory) with “tarâ€
tar -vcf archive_name.tar name_of_file
tar: the command
vcf: the options
v :provides a description of archived content (optional)
c: to create an archive
f: to specify a name for the archive(in parameter)
archive_name.tar: name given to the archive (the argument)
name_of_file: name of the folder (or directory) to be archived
Unpacking file with tar
The
tar command is also used to unpack the files, ie to extract all the individual files contained in an archive file.
Unpack the file with tar
tar-vxf my_file.tar
tar: the command
vxf: the options
v:provides a description of the unpacked files (optional)
x:to extract the files
f:to designate the archive containing the files (given parameter)
my_file.tar: the name of the archive to retrieve
Unpacking specific files with "tar"
Example:
You can also unpack only part of a
“tar†archive and extract specific files.
tar -xvf my_archive.tar "*.jpg"
Extract in the file "
my_archive" all files with the
.jpg extension ".
For a list of all files in the archive, use the "
-t".
tar -tf my_file.tar