Using archiver TAR in Linux Mint

Using archiver TAR in Linux Mint

tar is one of the tools that we use often to create backups. In this article I will give examples of using tar in Linux Mint. Amendment: these commands work in all versions of Linux Mint. Not only in Linux Mint))))

By itself, tar is not a archiver in the usual sense of the word, because he does not use compression. At the same time, many file compression software (such as Gzip or bzip2) do not know how to compress multiple files and work with only one file or input stream. Therefore, most of these programs are used together. tar creates an uncompressed archive to store the selected files and directories while keeping some of their attributes (such as access rights). The resulting file *.tar is compressed by a compression tool such as gzip. That is why the archives usually have the extension .tar.gz or .tar.bz2 (tar gzip and bzip2, respectively)

We all used to use the software (control program file archives) using the GUI, but sometimes at the most inopportune moment a situation arises where a convenient and beautiful interface favorite desktop is unavailable. Then comes the old good console. And so, let’s say in front of us naked the console, the command “ls” showed a list of files, among which are necessary to us, for example, driver.tar.gz. In the last packaged the driver of your video card required for operation of the graphics server. What, hurry to unpack them faster, because boring and uninteresting console already pretty tired. For these purposes, provided the tar command.

Options for TAR:


To create an archive.

Create a file output (otherwise it goes to the terminal).

To use bzip2 compression.

Use xz compression.

Use lzma compression.

To use gzip compression.

The output in the terminal what happens (action).

To retrieve:

Extracting the archive.

The output in the terminal what happens (action).

Preserve permissions when extracting (ignore mask).

Do not overwrite existing files.

Not to restore the modification time.

To record on the recording”entries” to stdout, not a restore disk.

Other options:

Get the table of contents (contents) from the archive.

The difference between archive and file system.

Use #512 byte records in the I/O blocks.

Option is used to check the archive.

The interactive mode.

Click to add files to an archive (already created).

Other interesting options of this very important commands can be found in the user guide:

man tar
tar –help

Therefore, by using the TAR command with the following parameters I will unpack the archive with the driver:

tar -xvzf driver.tar.gz

Other examples:

Create archive directory:

tar -cf directory.tar directory/

To create an archive with multiple files (selected files):

tar -cf directory.tar file1 file2 file3

Pack only .mp3 files in the current directory using BZIP compression and show everything that happens on the console:

tar -cvf my_mp3_collection.tar ./*.mp3

To create an archive of your home directory /home/user/ and keeping the right files:

tar -cvpf user.tar /home/user/

To create an archive of the /etc/ directory , but exclude the directory apache2:

tar -cvf backup_etc_without_apache_folder.tar –exclude=’/etc/apache2/’

will pack the folder ~/files with all contents in a compressed gzip archive

tar -cvzf files.tar.gz ~/files

will create the same archive using bzip2 compression

tar -cvjf files.tar.bz2 ~/files

Key v includes a list of Packed files in the process. Unfortunately, more advanced display process (e.g., indicating the extent of readiness in percent) in tar is not provided. To do this, use graphic archivers.
In addition to gzip and bzip2 can be used, for example, lzma (key lzma) or xz (J), while the corresponding archiver must be installed in the system.

The action of “unpackingis specified using key -x. And here again you will need the -f to specify the file name of the archive. Also add the -v switch to the visual display of the process.

tar -xvf /path/to/archive.tar.bz2

unpack the archive contents to the current folder. Alternative place to decompress, you can specify by using the-C switch:

tar -xvf archive.tar.bz2 -C /path/to/folder

To view the contents of the archive use the following command:

tar -tf archive.tar.gz

It displays a simple list of files and directories in the archive. If we add the -v switch, it will display a detailed list indicating size, access rights and other parameters (the same as in ls -l) 

To add files or directories to an existing tar archive files, we use the -r option:

tar -rvf linux-notes.tar test.txt

To check the contents of an archive, use the-W option as shown in the example below:

tar -tvfW linux-notes.tar
Share to friends
Rate author
( No ratings yet )
Notify of
Inline Feedbacks
View all comments