How to Install and Use the tar Tool on RHEL 8

How to Install and Use the tar Tool on RHEL 8
How to Install and Use the tar Tool on RHEL 8

How to Install and Use the tar Tool on RHEL 8 - tar is an abbreviation for "tape archive" and is a utility command in the Linux operating system used to create and manipulate archive files. Archive files created by tar are often referred to as "tarballs".

tar is already installed by default on most Linux distributions, so chances are you already have tar on your system. To check if tar is installed, you can run the following command in the terminal:

# tar --version

tar --version
tar --version

Install or Upgrade Version.

If tar is already installed, the version of tar and related information will be displayed. If it is not installed, you can install it using the package manager that is appropriate for the Linux distribution you are using. Here are some examples of commonly used package managers:

# yum update
# yum install tar

After installing tar, you can use the aforementioned commands to create, extract, and manipulate archive files in Linux.

How to Use tar.

To archive and extract files using tar, here are examples of how to use it:

1. Archive file/folder:

# tar -cvf name_of_file.tar file1 file2 directory

Example:

# tar -cvf archive.tar file1.txt file2.txt folder/

tar -cvf archive.tar file1.txt file2.txt folder/
tar -cvf archive.tar file1.txt file2.txt folder/

The above command will create an archive file named name_of_file.tar containing file1.txt, file2.txt, and the contents of the folder/ directory.

2. Extract file/folder from the archive:

# tar -xvf name_of_file.tar

Example:

# tar -xvf archive.tar

tar -xvf archive.tar
tar -xvf archive.tar

The above command will extract all files and directories from name_of_file.tar into the current directory.

3. Extract specific file/folder from the archive:

# tar -xvf name_of_file.tar file1 file2

Example:

# tar -xvf archive.tar file1.txt file2.txt

The above command will extract only file1.txt and file2.txt from name_of_file.tar.

4. Extract file/folder with filter using pattern:

# tar -xvf name_of_file.tar --wildcards 'pattern'

Example:

# tar -xvf archive.tar --wildcards '*.txt'

The above command will extract all files with the .txt extension from name_of_file.tar.

These are basic examples for archiving and extracting files using tar. Make sure to replace name_of_file.tar with the appropriate file name. Also, you can combine other available options in tar as per your needs. You can check the tar documentation by running man tar for more information on usage and available options.

Archive a folder using tar on CentOS.

Open the terminal or access your CentOS server via SSH.

To archive the folder into a tar file, use the following command:

# tar -cvf name_of_file.tar folder/

Replace name_of_file.tar with the desired name for the archive file, and folder/ with the full path to the folder you want to archive.

Example:

# tar -cvf archive.tar /path/to/folder/

The above command will create an archive file named archive.tar containing all the contents of the specified folder.

Extract archived the folder.

You can extract files from the archive using the following steps:

Open the terminal or access your CentOS server via SSH.

To extract the contents of the tar archive, use the following command:

# tar -xvf name_of_file.tar

Replace name_of_file.tar with the name of the archive file you want to extract.

Example:

# tar -xvf archive.tar

The above command will extract all the contents of the archive.tar into the current directory.

Extract the archive to a different directory.

Use the -C option followed by the path to the destination directory. For example:

# tar -xvf archive.tar -C /path/to/destination/

The above command will extract the contents of the archive.tar into the /path/to/destination/ directory.

tar -xvf archive.tar -C /home/kitsake/destination/
tar -xvf archive.tar -C /home/kitsake/destination/

That's how you archive and extract a folder using tar on CentOS. Make sure to replace nama_file.tar and folder/ according to your needs.

Closing statement

In conclusion, mastering the installation and usage of the 'tar' tool on RHEL 8 equips Linux users with essential skills for creating and manipulating archive files effectively. 

Whether archiving files or extracting specific contents from tarballs, the commands provided offer a comprehensive guide to streamline file management tasks on the command line. 

By following the examples and understanding the versatility of 'tar', users can optimize their workflow and enhance their productivity in handling compressed data.

Maybe that's all I can share with you guys, hopefully this article will be useful.

Thank You 

Bangkit Ade Saputra
Bangkit Ade Saputra At the end of the day, my job involves people. we're complicated, we're always changing, we have millions of things going on in our lives, and changing jobs is always a big decision.

Post a Comment for "How to Install and Use the tar Tool on RHEL 8"