How To Extract Tar Files To Specific or Different Directory in Linux
How To Extract Tar Files To Specific or Different Directory in Linux
Linux Distro’s FAQ’s Programming Linux Commands Linux Tricks Best Linux Tools Certi cations Guides Monitoring Tools
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.
Privacy
One thing to understand is that you can extract tar les to a different or speci c 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.
In this guide, we shall take a look at how to extract tar les to a speci c or different directory, where you want
the les to reside.
Note: In the above rst syntax, the -C option is used to specify a different directory other than the current
working 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.
# mkdir -p /tmp/tgz
# mkdir -p /tmp/tar.bz2
# mkdir /backup/tar_extracts
# tar -xvf etc.tar etc/issue etc/fuse.conf etc/mysql/ -C /backup/tar_extracts/
Summary
That is it with extracting tar les to a speci c directory and also extracting speci c les from a tar le. If you
nd this guide helpful or have more information or additional ideas, you can give me a feedback by posting a
comment.
How to Use 8 Useful ‘Debian Goodies Utilities’ to Manage How to Use ‘Tmux Terminal’ to Access Multiple Terminals
Debian Packages Inside a Single Console
If you liked this article, then do subscribe to email alerts for Linux tutorials. If you have any questions or
doubts? do ask for help in the comments section.
TecMint is the fastest growing and most trusted community site for any kind of Linux
Articles, Guides and Books on the web. Millions of people visit TecMint! to search or
browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token
of appreciation.
Related Posts
How to Use fgrep Command 12 Practical Examples of An Easy Way to Hide Files
to Search for Strings in Linux Linux Grep Command and Directories in Linux
How to Use ‘dir’ Command Linux mkdir Command 20 Linux egrep Command
with Different Options and Examples Examples
Arguments in Linux
Pascal
April 16, 2021 at 10:42 am
Great article.
Just to note that “Example 4: Extract Only Speci c or Selected Files from Tar Archive” is the wrong
syntax.
The order of the arguments has to be changed. The single les or directories to be extracted need to
be last:
It shall read
Reply
Your blog is very good, your blog has great information, your content is also very good, your blog has
got a lot of help.
Reply
Aaron Kili
February 10, 2019 at 2:29 pm
@SHIVANI
I would like you to know that we are pleased to have read your beautiful and kind note of
appreciation and encouragement.
Reply
Jalal Hajigholamali
January 6, 2016 at 12:22 pm
Hi,
tar command accepts options without minus[-] sign
also ‘-j’ option is optional and can be ignore….
example:
tar xvf …..
Thanks a lot
Reply
Aaron Kili
January 9, 2016 at 3:48 am
Reply
Ren
January 3, 2016 at 6:26 am
When I extract only speci c les from Tar archive, ‘-C’ option is doesn’t work.
Reply
Ravi Saive
January 4, 2016 at 11:06 am
@Ren,
Have you created the separate directory before extracting the speci c les to that directory?
The -C option is used to specify a different directory and it must exists before extracting les.
For example,
Else, you can also extract les withing the current directory without creating a new directory
like:
powertop-2.7/m4/po.m4
Reply
Eric
November 1, 2017 at 8:30 pm
I have the same issue as @Ren, and in my case I have created the destination dir… no
matter how I specify things the extracted le always ends up in the current directory.
Reply
Eric
November 1, 2017 at 8:34 pm
Oh… if I change the order it works. If I move the “–directory ” earlier in the args, it works.
Reply
David
January 3, 2016 at 12:27 am
In the last example, extracting several les from the etc directory out of the tar le, what is the cts/ in
the rst line of the extracted les?
Reply
Konrad
January 2, 2016 at 10:50 pm
Great post. It would be helpful for Linux beginners to explain the switches used. What does -xf do?
You explain the addition of the -v switch which is good. What’s the difference between -C and –
directory? In Example 2, you throw in the -z switch and in Example 3, the -j switch without any
explanation. Then in example 4, you talk about extracting single les, yet the command also includes
an option to extract all les in a speci c directory – etc/mysql/. Again, a good example for using
different options, but it could use a bit of explanation.
Reply
Ravi Saive
January 4, 2016 at 11:11 am
@Konrad,
Yes, we haven’t speci ed the meaning of each tar command option used in these examples,
the reason because we’ve already requested users to read the article that says Mastering tar
Command with this 18 Examples in Linux, before heading up further. No issue you can nd all
these options explanation below:
Reply
Name *
Email *
Save my name, email, and website in this browser for the next time I comment.
Post Comment
Linux Server Monitoring Tools Learn Linux Tricks & Tips Best Linux Tools
How to Monitor Ubuntu Performance Using How to Test Website Loading Speed in Linux 3 Useful GUI and Terminal Based Linux Disk
Netdata Terminal Scanning Tools
How to Install Icinga2 Monitoring Tool on Ways to Use ‘ nd’ Command to Search 8 Best Video Editing Softwares I Discovered
Ubuntu 20.04/22.04 Directories More Ef ciently for Linux
httpstat – A Curl Statistics Tool to Check How to Download MP3 Tracks from a Best RDP (Remote Desktop) Clients for Linux
Website Performance YouTube Video Using YouTube-DL
8 Top Open Source Reverse Proxy Servers for
systemd-analyze – Find System Boot-up How to Run MySQL/MariaDB Queries Directly Linux
Performance Statistics in Linux from the Linux Command Line
10 Best Clipboard Managers for Linux
LibreNMS – A Fully Featured Network 7 Ways to Determine the File System Type in
5 Most Notable Open Source Centralized Log
Monitoring Tool for Linux Linux (Ext2, Ext3 or Ext4)
Management Tools
Swatchdog – Simple Log File Watcher in How to Block or Disable Normal User Logins
Real-Time in Linux in Linux
Donate to TecMint Contact Us Advertise on TecMint Linux Services Copyright Policy Privacy Policy Career Sponsored Post
Tecmint: Linux Howtos, Tutorials & Guides © 2022. All Rights Reserved.
The material in this site cannot be republished either online or of ine, without our permission.