What is .tar package in Linux ?
1) .tar
package, commonly referred to as a "tarball," is an archive file format used on Unix-like operating systems, including Linux
2) It is a way to package multiple files and directories into a single file for storage, distribution, or backup purposes .
3) The term "tar" stands for "tape archive," harking back to the early days of Unix when data was often stored on magnetic tapes.
Here are some key characteristics of a .tar
package:
1)Archiving Files: A .tar
file is used to bundle multiple files and directories together into a single archive. This makes it easier to manage and transfer collections of files.
2) No Compression: By default, a .tar
file does not perform compression. It simply collects the files and directories into a single file. Therefore, .tar
files tend to be larger in size compared to compressed archive formats like .zip
, .gzip
, .bzip2
, or .xz
For Example :- I have Three files in in folder of 1 MB,500KB ,100KB .Total size is 1.6 MB
as shown :-
Now i will create a .tar folder name tarfolder.tar by
/tar -cvf tarfolder file1 file2 file3
where -c: This flag stands for "create." It tells tar
to create a new archive.
-v: This flag stands for "verbose." When you include it,
tar
will display detailed information about the files it's archiving as it creates the archive. It provides a list of the files being added to the archive, which can be helpful for tracking progress.-f: This flag stands for "file." It is followed by the name of the archive file you want to create. For example, if you want to create an archive called "tarfolder.tar," you would specify it as
Now let's compare the size as total size before and after are same as 1.6 MB
we can determine tar only makes the files in one folder but do not compress the file.
now to untar the file we need to use the same command but instead of cvf we use xvf where
-x
: This option tellstar
to extract the contents.-v
: This option enables verbose mode, which shows the progress of the extraction.-f
: This option specifies the name of the tar file you want to extract (replaceyourfile.tar
with the actual filename.-
-C is used for where you want to extract the folder.
3 ) Common Extensions:
.tar
files often have extensions like.tar
or.tar.gz
to indicate whether they are compressed. For example, a.tar.gz
file is a compressed.tar
archive.4) Preservation of File Attributes:
.tar
archives preserve file metadata such as permissions, ownership, timestamps, and directory structure. This makes them suitable for creating backups and preserving file attributes.
5) Common Usage: .tar
archives are commonly used in the Linux and Unix world for distributing software source code, creating backup archives, and packaging files for distribution. When combined with compression tools like gzip
, bzip2
, or xz
, they can create compressed archive files with the extension .tar.gz
, .tar.bz2
, or .tar.xz
, respectively.
Let's create the .tar.gz and see how much it compresses the files
// tar -czvf tarfolder.ta r.gz untarfolder
gzip file creation
gzip filename
bzip2 file creation
bzip2 file.txt
or
bzip2 -c my_file.txt > compressed_file.bz2
or
tar -cjvf compressed_archive.tar.bz2 file1 file2 directory/
Do read and if you have any points you want me to add or correct just comment on the post