install tar.gz on almalinux 9

How to Install Tar.gz on AlmaLinux 9

Spread the love

If you are asking what is Tar.gz, then the tar file is an archive that contains files and folders into it, while the gz stands for the compressed file format. If you combine these two, you will get a compressed archive.

The compressed archives are used on a daily basis by the system administrators, developers, and regular Linux users. Compressing multiple files in one archive can simplify the process of sending that compressed file quickly.

In this blog post, we will install and show you some real-life examples of using the tar.gz format with commands. Let’s get started!

  • A server with AlmaLinux 9 as OS
  • User privileges: root or non-root user with sudo privileges

Update the System

We assume that you have a fresh installation of AlmaLinux 9 so let’s first update the system packages to their latest versions available:

sudo dnf update -y && sudo dnf upgrade -y

Tar.Gz Installation

Tar.Gz can be installed and is compatible with multiple operating systems such as MacOS, Windows and Linux. We will focus of course Linux operating system because AlmaLinux is a Linux distribution. To install tar.gz on AlmaLinux 9, execute the following command:

yum install tar gzip

Once installed, you can check the installed versions of tar and gzip using the following commands:

tar --version

gzip --version

You should get the following output:

[root@host ~]# tar --version
tar (GNU tar) 1.34
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later .
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by John Gilmore and Jay Fenlason.
[root@host ~]# gzip --version
gzip 1.12
Copyright (C) 2018 Free Software Foundation, Inc.
Copyright (C) 1993 Jean-loup Gailly.
This is free software.  You may redistribute copies of it under the terms of
the GNU General Public License .
There is NO WARRANTY, to the extent permitted by law.

Written by Jean-loup Gailly.

How to create Tar.gz files

Now, when the tar.gz is installed, we are going to show you how to create a tar.gz file. Let’s say that we have WordPress files and folders:

[root@host wordpress]# ll
total 228
-rw-r--r--  1 root root   405 Feb  6  2020 index.php
-rw-r--r--  1 root root 19915 Dec 31 18:06 license.txt
-rw-r--r--  1 root root  7402 Mar  4 18:52 readme.html
-rw-r--r--  1 root root  7205 Sep 16  2022 wp-activate.php
drwxr-xr-x  9 root root  4096 May 16 11:45 wp-admin
-rw-r--r--  1 root root   351 Feb  6  2020 wp-blog-header.php
-rw-r--r--  1 root root  2338 Nov  9  2021 wp-comments-post.php
-rw-r--r--  1 root root  3013 Feb 23 04:38 wp-config-sample.php
drwxr-xr-x  4 root root  4096 May 16 11:45 wp-content
-rw-r--r--  1 root root  5536 Nov 23 09:43 wp-cron.php
drwxr-xr-x 28 root root 12288 May 16 11:45 wp-includes
-rw-r--r--  1 root root  2502 Nov 26 15:01 wp-links-opml.php
-rw-r--r--  1 root root  3792 Feb 23 04:38 wp-load.php
-rw-r--r--  1 root root 49330 Feb 23 04:38 wp-login.php
-rw-r--r--  1 root root  8541 Feb  3 07:35 wp-mail.php
-rw-r--r--  1 root root 24993 Mar  1 09:05 wp-settings.php
-rw-r--r--  1 root root 34350 Sep 16  2022 wp-signup.php
-rw-r--r--  1 root root  4889 Nov 23 09:43 wp-trackback.php
-rw-r--r--  1 root root  3238 Nov 29 09:51 xmlrpc.php

We want to compress them in an archive so we can easily upload somewhere or store them locally on our system. To do that, execute the following command inside the WordPress directory:

tar -zcvf wordpress.tar.gz .

This will compress all files and folders of the current directory (That is why we are using dot in the command), and the compressed file will be inside it:

[root@host wordpress]# ll
total 22700
-rw-r--r--  1 root root      405 Feb  6  2020 index.php
-rw-r--r--  1 root root    19915 Dec 31 18:06 license.txt
-rw-r--r--  1 root root     7402 Mar  4 18:52 readme.html
-rw-r--r--  1 root root 23007861 May 19 15:06 wordpress.tar.gz
-rw-r--r--  1 root root     7205 Sep 16  2022 wp-activate.php
drwxr-xr-x  9 root root     4096 May 16 11:45 wp-admin
-rw-r--r--  1 root root      351 Feb  6  2020 wp-blog-header.php
-rw-r--r--  1 root root     2338 Nov  9  2021 wp-comments-post.php
-rw-r--r--  1 root root     3013 Feb 23 04:38 wp-config-sample.php
drwxr-xr-x  4 root root     4096 May 16 11:45 wp-content
-rw-r--r--  1 root root     5536 Nov 23 09:43 wp-cron.php
drwxr-xr-x 28 root root    12288 May 16 11:45 wp-includes
-rw-r--r--  1 root root     2502 Nov 26 15:01 wp-links-opml.php
-rw-r--r--  1 root root     3792 Feb 23 04:38 wp-load.php
-rw-r--r--  1 root root    49330 Feb 23 04:38 wp-login.php
-rw-r--r--  1 root root     8541 Feb  3 07:35 wp-mail.php
-rw-r--r--  1 root root    24993 Mar  1 09:05 wp-settings.php
-rw-r--r--  1 root root    34350 Sep 16  2022 wp-signup.php
-rw-r--r--  1 root root     4889 Nov 23 09:43 wp-trackback.php
-rw-r--r--  1 root root     3238 Nov 29 09:51 xmlrpc.php

The original WordPress directory was 72 megabytes:

[root@host html]# du -csxh wordpress/
72M     wordpress/
72M     total

Now, the compressed file is 22 megabytes which is three times smaller than the WordPress directory:

[root@host wordpress]# du -csxh wordpress.tar.gz
22M     wordpress.tar.gz
22M     total

How to Extract Tar.gz Files

To extract the compressed tar.gz archive, execute the following command:

tar -xzvf wordpress.tar.gz

You can notice now that instead of the c flag, the x flag is used, which means extract.

If you want to know more about the usage of tar, you can execute the following command:

man tar

You should get the following output:

[root@host ~]# man tar
TAR(1)                                                                     GNU TAR Manual                                                                    TAR(1)

NAME
       tar - an archiving utility

SYNOPSIS
   Traditional usage
       tar {A|c|d|r|t|u|x}[GnSkUWOmpsMBiajJzZhPlRvwo] [ARG...]

   UNIX-style usage
       tar -A [OPTIONS] ARCHIVE ARCHIVE

       tar -c [-f ARCHIVE] [OPTIONS] [FILE...]

       tar -d [-f ARCHIVE] [OPTIONS] [FILE...]

       tar -t [-f ARCHIVE] [OPTIONS] [MEMBER...]

       tar -r [-f ARCHIVE] [OPTIONS] [FILE...]

       tar -u [-f ARCHIVE] [OPTIONS] [FILE...]

       tar -x [-f ARCHIVE] [OPTIONS] [MEMBER...]
          .
          .
          .
          .
          .

That’s it. In this blog post, we explained how to install Tar.gz on AlmaLinux 9 and its usage. If you find it difficult to install and use the tar command, you can always sign up for one of our NVMe VPS plans and submit a support ticket. We are available 24/7

If you liked this post about installing Tar.gz on AlmaLinux 9, please share it with your friends on social networks or simply leave a reply below.

Leave a Reply

Your email address will not be published. Required fields are marked *