• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Friday, May 9, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System Linux

How to Extract Tar Files to Specific or Different Directory in Linux

How VPS by How VPS
November 2, 2018
in Linux
0
0
SHARES
49
VIEWS
Share on FacebookShare on Twitter

Contents

  1. Example 1: Extracting tar Files to a Specific Directory
  2. Example 2: Extract .tar.gz or .tgz Files to Different Directory
  3. Example 3: Extract tar.bz2, .tar.bz, .tbz or .tbz2 Files to Different Directory
  4. Example 4: Extract Only Specific or Selected Files from Tar Archive
  5. Summary

The tar utility is one of the utilities that you can use to create a backup on a Linux system. It includes many options that one can use to specify the task to achieve.

How to Extract Tar Files to Specific or Different Directory in Linux

Extract Linux Tar Files Different or New Directory

One thing to understand is that you can extract tar files to a different or specific directory, not necessarily the current working directory. You can read more about tar backup utility with many different examples in the following article, before proceeding further with this article.

Mastering tar Command with this 18 Examples in Linux

In this guide, we shall take a look at how to extract tar files to a specific or different directory, where you want the files to reside.

The general syntax of tar utility for extracting files:

# tar -xf file_name.tar -C /target/directory
# tar -xf file_name.tar.gz --directory /target/directory

Note: In the above first syntax, the -C option is used to specify a different directory other than the current working directory.

Let us now look at some examples below.

Example 1: Extracting tar Files to a Specific Directory

In the first example, I will extract the files in articles.tar to a directory /tmp/my_article. Always make sure that the directory into which you want to extract tar file exists.

Let me start by creating the /tmp/my_article directory using the command below:

# mkdir /tmp/my_article

You can include the -p option to the above command so that the command does not complain.

To extract the files in articles.tar to /tmp/my_article, I will run the command bellow:

# tar -xvf articles.tar -C /tmp/my_article/
How to Extract Tar Files to Specific or Different Directory in Linux

Img 01: Extract Tar Files to Different Directory

In the above example I used the -v option to monitor the progress of the tar extraction.

Let me also use the --directory option instead of -c for the example above. It works just in the same way.

# tar -xvf articles.tar --directory /tmp/my_articles/
How to Extract Tar Files to Specific or Different Directory in Linux

Img 02: Extract Tar Files to Specific Directory

Example 2: Extract .tar.gz or .tgz Files to Different Directory

First make sure that you create the specific directory that you want to extract into by using:

# mkdir -p /tmp/tgz

Now we will extract the contents of documents.tgz file to separate /tmp/tgz/ directory.

# tar -zvxf documents.tgz -C /tmp/tgz/ 
How to Extract Tar Files to Specific or Different Directory in Linux

Img 03: Extract tar.gz or .tgz Files to Different Directory

Example 3: Extract tar.bz2, .tar.bz, .tbz or .tbz2 Files to Different Directory

Again repeating that you must create a separate directory before unpacking files:

# mkdir -p /tmp/tar.bz2

Now we will be unpacking the documents.tbz2 files to /tmp/tar.bz2/ directory.

# tar -jvxf documents.tbz2 -C /tmp/tar.bz2/ 
How to Extract Tar Files to Specific or Different Directory in Linux

Img 04: Extract tar.bz2 Files to Different Directory

Example 4: Extract Only Specific or Selected Files from Tar Archive

The tar utility also allows you to define the files that you want to only extract from a .tar file. In the next example, I will extract specific files out of a tar file to a specific directory as follows:

# mkdir /backup/tar_extracts
# tar -xvf etc.tar etc/issue etc/fuse.conf etc/mysql/ -C /backup/tar_extracts/
How to Extract Tar Files to Specific or Different Directory in Linux

Img 05: Extract Specific Files From Tar Archive

Summary

That is it with extracting tar files to a specific directory and also extracting specific files from a tar file. If you find this guide helpful or have more information or additional ideas, you can give me a feedback by posting a comment.

Source: tecmint.com

Tags: Linux Commandslinux guidelinux vps setup guide
Previous Post

Full Disk Encryption

Next Post

10 Lesser Known Commands for Linux – Part 3

Next Post

10 Lesser Known Commands for Linux – Part 3

Leave a Reply Cancel reply

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

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Thabet