Tar archiver in Linux: how the classic file storage tool works

12.12.2025 9 minutes Author: Lady Liberty

The tar archiver remains one of the basic tools in Linux and other Unix-like systems. This article discusses the principle of operation of tar, the logic of creating archives and the features of interaction with the file system. The material will help to understand why tar is considered a standard in the Linux environment and in which scenarios it remains an indispensable tool for working with data.

What is tar and why is it still needed in modern Linux systems

The tar utility was originally used to create archives on magnetic tape (tar – tape archive). Currently, tar is used to create archives on any media and is practically the main means of storing files and directories in one file of a special format. The main advantage of the tar format is that the archive contains not only the data of the files being archived, but also information about the directory structure, the owner, and timestamps (creation, modification, access time). The tar archiver does not compress the archived data, it only packs many files into one file, the size of which is approximately equal to the total size of the packed files (a little more due to the addition of its own service headers). For compression, external programs are used ( gzip, bzip2, etc. )

To get a hint on how to use tar, it is enough to call the built-in help. It displays a brief description of the program’s purpose and basic command line parameters.

tar –help

The response will show the basic syntax for using the utility and tips for restoring individual files from the archive.

Використання: tar [ПАРАМЕТР...] [Файл] на файл . для відновлення окремих файлів із архіву.

Basic Usage Examples

The simplest commands allow you to quickly create archives, view their contents, or extract files.

tar -cf archive.tar foo bar

This command creates an archive.tar file containing the files foo and bar.

tar -tvf archive.tar

Displays a detailed list of all files and directories stored in the archive.

tar -xf archive.tar

Extracts all files from archive.tar into the current directory.

Main operating modes

Working with archives in tar is built around a few key modes. They determine what exactly will be done with the archive – creating, viewing, or extracting.

  • -c, –create — create a new archive

  • -t — view the contents of an archive

  • -x, –extract, –get — extract files from an archive

  • -r, –append — add files

  • -u, –update — add only new files

  • -A, –catenate, –concatenate — append tar files to an archive

These modes are usually sufficient for most everyday tasks.

Incremental archiving and modifiers

For backups, tar supports an incremental mode, which allows you to save only files that have changed since the previous archive. This is especially useful for regular backups.

  • -g, –listed-incremental=FILE — incremental backup of the new GNU format

  • -G, –incremental — incremental backup of the old format

  • –check-device / –no-check-device — check device numbers

  • –ignore-failed-read — do not stop on read errors

Options for working with sparse files and duplicate entries are also available:

  • -S, –sparse

  • –sparse-version=MAJOR[.MINOR]

  • –occurrence[=N]

File overwriting control

When extracting archives, it is often important to control whether existing files are overwritten. tar provides a separate group of options for this.

  • -k, –keep-old-files — do not overwrite existing files

  • –overwrite / –overwrite-dir — force overwrite

  • –no-overwrite-dir — preserve directory metadata

  • -U, –unlink-first — delete file before extracting

  • -W, –verify — verify archive after writing

Output streams and file attributes

If necessary, you can redirect the results of your work or change the behavior of saving attributes.

  • -O, –to-stdout — output files to the standard stream

  • –to-command=COMMAND — transfer files to another program

  • –atime-preserve — preserve access time

  • –numeric-owner — use numeric UID/GID

  • –no-same-owner / –no-same-permissions — control access rights

Archive formats and compression

tar supports several standard archive formats and can work with external compression programs.

Archive formats:

  • gnu

  • pax (POSIX)

  • ustar

  • v7

Compression options:

  • -a, –auto-compress — automatic type detection

  • -z, –gzip

  • -j, –bzip2

  • –lzma, –lzip

For a quick guide on how to use tar, type the command:

tar –usage

When you run this command, the options for using command line parameters are displayed without any explanation:

Використання: tar [-AcdrtuxGnSkUWOmpsMBiajJzZhPlRvwo?]
[-g ФАЙЛ] [-g ФАЙЛ] [-g [-b БЛОКИ]
[-H ФОРМАТ] [-V ТЕКСТ] [-I ПРОГ]
[-C КАТАЛОГ] [-K ІМ'Я-ЧЛЕНА]
[-N ДАТА-АБО-ФАЙЛ] [-T ФАЙЛ
] [-X ФАЙЛ] [--catenate] [--concatenate]
[--create] [--append] [--list] [--test-label] [--update]
[--extract] [--get] [--check-device]
[--listed-incremental=ФАЙЛ] [--incremental]
[--ignore-failed-read] [--level=N] [--seek]
[--no- [--occurrence[=N]] [--sparse-version=MAJOR[.MINOR]]
[--sparse] [--keep-old-files] [--keep-newer-files]
[--no-overwrite-dir] [--overwrite] [--overwrite-dir]
[--recurs [--skip-old-files]
[--unlink-first] [--verify] [--ignore-command-error]
[--no-ignore-command-error] [--to-stdout]
[--to-command=КОМАНДА] [--acls]
[--atime-preserve[=СПОСОБ]]
[--group=ІМ'Я] [--mode=РЕЖИМ]
[--mtime=ДАТА-АБО-ФАЙЛ] [--touch] [--no-acls]
[--no-delay-directory-restore] [--no-same-owner]
[--no-same-permissions]
[--no- selinux [--owner=ІМ'Я] [--preserve-permissions]
[--same-permissions] [--preserve] [--same-owner]
[--preserve-order] [--same-order] [--selinux] [--xattrs]
[--file=АРХІВ] [--force-local] [--info-script=ІМ'Я]
[--new-volume-script=ІМ'Я] [--tape-length=N]
[--multi-volu [--rsh-command=КОМАНДА]
[--volno-file=ФАЙЛ] [--blocking-factor=БЛОКИ]
[--read-full-records] [--ignore-zeros] [--record-size=N]
[--format=ФОРМАТ] [--old-archive] [--portability
[--pax-option=keyword[=значення][,keyword[=значення]]...]
[--posix] [--label=ТЕКСТ] [--auto-compress]
[--use-compress-program=ПРОГ] [--bzip2]
[--xz] [--lzip] [--lzma [--gzip] [--gunzip]
[--ungzip] [--compress] [--uncompress] [--add-file=ФАЙЛ]
[--backup[=УПРАВЛІННЯ]] [--directory=КАТАЛОГ]
[--exclude=ШАБЛОН] [
--exclude-backups] [--exclude-ca [--exclude-caches-under]
[--exclude-tag=ФАЙЛ] [--exclude-tag-all=ФАЙЛ]
[--exclude-tag-under=ФАЙЛ] [--exclude-vcs] [--dereference]
[--hard-dereference]
[--starting-file=ІМ'Я-ЧЛЕНА] [-- [--no-recursion]
[--no-unquote] [--null] [--newer=ДАТА-АБО-ФАЙЛ]
[--after-date=ДАТА-АБО-ФАЙЛ] [--one-file-system]
[--absolute-names] [--recursion] [--suffix
=ФРОК] [--exclude-from=ФАЙЛ]
[--strip-components=N] [--transform
=РОЗШИРЕННЯ] [--xform=РОЗШИРЕННЯ] [--anchored] [--ignore-case]
[--no-anchored] [--no-ignore-case] [
--no-wildcard [--wildcards]
[--wildcards-match-slash] [--checkpoint[=N]]
[--checkpoint-action=ДІЯ] [--index-file=ФАЙЛ]
[--check-links] [--no-quote-chars=РЯДОК
] [--quote-chars=РЯДОК
[--block-number] [--show-defaults] [--show-omitted-dirs]
[--show-transformed-names] [--show-stored-names]
[--totals[=СИГНАЛ]] [--utc] [--verbose] [--warning=
KEYWORD [--restrict] [--usage]
[--version] [ФАЙЛ]...

You can also use the built-in help system:

man tar

Examples of using tar

tar -create -file=archive.tar file1 file2 – create an archive archive.tar from files ffile1 and file2 in the current directory

tar -cf archive.tar file1 file2 – the same as in the previous example, but using the syntax of short options (shortened command line parameters: -c corresponds to options, they can be combined – the parameters -c -f file.tar can be entered as -cf file.tar . tar -cvf archive.tar file1 of the user’s home directory. When using this command format, the question often arises why tar does not include hidden files and directories in the archive, the names of which begin with a dot. file or group of files. The definition of objects suitable for the template is handled by the command shell itself, in which, for security reasons, The “*” pattern does not include file names that begin with a period. tar -zcvf /backup/archive.tar.gz /home/user/ – create an archive of all files in the user’s home directory using gzip compression tar -jcvf /backup/archive.tar.bz2 /home/user/ – create an archive of all files in the user’s home directory using /backup/archive.tar.bz2 /home/user/ – create an archive of all files in the user’s home directory using a program that is automatically determined by the file name.

If the archive file name does not specify a compression program, the archive is created but compression is not performed. When unpacking an archive, the -a parameter is not required, as the compression type is determined automatically in any case:

  • tar -tvf archive.tar – display a list of files and directories in the archive.tar

  • tar -tvf archive.tar > listfiles – the same as in the previous example, but with the results output to the text file listfiles

  • tar -xvf archive.tar – unpack (unarchive) the contents into the current directory

  • ./backup/archive.tar –C /home2/ – extract the contents of the archive /backup/archive.tar to the /home2 directory.

  • tar –xv –keep-newer-file –f /backup/archive.tar –C /home2 – the same as in the previous example, only existing files will not be overwritten if they are the same age or newer.

  • tar –xvkf /backup/archive.tar –C /home2 – if you try to overwrite an existing file while extracting data from the archive, the tar program will fail with an error.

  • tar –exclude=log -zcvf /backup/archive.tar.gz /var/ – exclude log files when archiving.

  • tar –exclude-backups –exclude-caches –exclude-tag-all=excludes.txt -zcvf /backup/home.tar.gz /home/ – exclude backup files, cache and all directories that contain a file named excludes.txt when archiving

The tar utility allows you to create tars that contain only files that have changed since a full or incremental backup. When using this archiving mode, the tar command is executed with the –listed-incremental=FILE parameter ( -g FILE ), where FILE points to a metadata file that stores information about the state of the incremental archive.

If such a file does not exist, the command creates a full archive and a new metadata file that will be used in subsequent stages of creating incremental backups.

  • tar -zcvf /backup/home.tar.gz –backup=numbered –listed-incremental=/backup/home_meta /home/ – create an incremental archive of the /home directory.

The –backup=numbered parameter indicates that numbered backups should be created.

The full archive, in this example, will be created as a file named home.tar.gz , and subsequent incremental archives will be created with the names home.tar.gz.~1~ , home.tar.gz.~2~ , etc.

To restore data from an incremental archive, you must first unarchive the full archive file, and then the incremental ones:

  • tar -zxvf /backup/home.tar.gz -C /home2 – extract the contents of the full archive to the /home2 directory.

  • tar -zxvf /backup/home.tar.gz.~1~ -C /home2 – get the contents of the first incremental archive to the /home2 directory.

  • tar -zxvf /backup/home.tar.gz.~2~ -C /home2 – get the contents of the second incremental archive to the /home2 directory.

Using incremental archiving in tar allows, for example, to create periodic backups automatically using a scheduler (daily, weekly, monthly, etc.).

Conclusion

tar is an example of a tool that does not become obsolete, even despite decades of development of the Linux ecosystem. Its strength is not in fashion or “convenient interface”, but in versatility, predictability and deep integration with the system. That is why tar is still used everywhere: from manual work of the administrator to automatic backups, from collecting packages and containers to server backups and CI/CD processes.

In modern Linux systems, tar remains a basic “building block”: it does not compress data on its own, but is perfectly combined with any compression algorithms; it does not hide details, but preserves all important meta-information; it is simple in basic use, but extremely flexible in complex scenarios. Support for incremental archiving is especially valuable, which allows you to build efficient and reliable backup systems without unnecessary overhead.

Subscribe
Notify of
0 Коментарі
Oldest
Newest Most Voted
Found an error?
If you find an error, take a screenshot and send it to the bot.